From 107 583 patients, matched cohorts demonstrated that those undergoing surgery were at significantly higher risk for depression, anxiety, suicidal ideation, and substance use disorders than those without surgery. Males with surgery showed a higher prevalence of depression (25.4% vs. 11.5%, RR 2.203, P < 0.0001) and anxiety (12.8% vs. 2.6%, RR 4.882, P < 0.0001). Females exhibited similar trends, with elevated depression (22.9% vs. 14.6%, RR 1.563, P < 0.0001) and anxiety (10.5% vs. 7.1%, RR 1.478, P < 0.0001). Feminizing individuals demonstrated particularly high risk for depression (RR 1.783, P = 0.0298) and substance use disorders (RR 1.284, P < 0.0001).