This study aimed to examine the association of prior mental health diagnoses with the onset of Post-COVID-19 condition (PCC). We conducted a retrospective comparative cohort study and secondary analysis of routinely collected claims data from participants in statutory health insurance in Bavaria, Germany, from January 2015 to June 2022. Study participants were 619,560 patients with confirmed COVID-19, 42,969 with other respiratory tract infection (ORI), and 438,023 controls. Using diagnoses coded according to the German modification of the ICD-10, the associations between prior mental health diagnoses and a PCC diagnosis (primary outcome) or associated symptoms (secondary outcomes) were estimated using multiple Cox proportional hazards regression models. Mental disorders (hazard ratio [HR] 1.36, 95% confidence interval [CI] 1.30–1.42), anxiety (HR 1.14, 95% CI 1.07–1.20), depression (HR 1.25, 95% CI 1.19–1.30) and somatoform disorders (HR 1.30, 95% CI 1.24–1.36) were associated with higher risks for PCC. Mental disorders were associated with the same or even greater risk for a diagnosis of malaise and fatigue in the control cohort (HR 1.71, 95% CI 1.52–1.93) and ORI cohort (HR 1.43, 95% CI 1.20–1.72), than in the COVID-19 cohort (HR 1.43, 95% CI 1.35–1.51). In summary, prior mental comorbidity was associated with an increased risk of PCC and its associated symptoms in all cohorts, not specifically in COVID-19 patients.