Despite evidence indicating increased risk of psychiatric issues among COVID-19 survivors, questions persist about long-term mental health outcomes and the protective effect of vaccination. Using UK Biobank data, three cohorts were constructed: SARS-CoV-2 infection (n = 26,101), contemporary control with no evidence of infection (n = 380,337) and historical control predating the pandemic (n = 390,621). Compared with contemporary controls, infected participants had higher subsequent risks of incident mental health at 1 year (hazard ratio (HR): 1.54, 95% CI 1.42–1.67; P = 1.70 × 10−24; difference in incidence rate: 27.36, 95% CI 21.16–34.10 per 1,000 person-years), including psychotic, mood, anxiety, alcohol use and sleep disorders, and prescriptions for antipsychotics, antidepressants, benzodiazepines, mood stabilizers and opioids. Risks were higher for hospitalized individuals (2.17, 1.70–2.78; P = 5.80 × 10−10) than those not hospitalized (1.41, 1.30–1.53; P = 1.46 × 10−16), and were reduced in fully vaccinated people (0.97, 0.80–1.19; P = 0.799) compared with non-vaccinated or partially vaccinated individuals (1.64, 1.49–1.79; P = 4.95 × 10−26). Breakthrough infections showed similar risk of psychiatric diagnosis (0.91, 0.78–1.07; P = 0.278) but increased prescription risk (1.42, 1.00–2.02; P = 0.053) compared with uninfected controls. Early identification and treatment of psychiatric disorders in COVID-19 survivors, especially those severely affected or unvaccinated, should be a priority in the management of long COVID. With the accumulation of breakthrough infections in the post-pandemic era, the findings highlight the need for continued optimization of strategies to foster resilience and prevent escalation of subclinical mental health symptoms to severe disorders.