An isolation strategy was used to control the transmission and rapid spread of COVID-19 in Yunnan. As a result, students were supposed to stay at home and disrupted their outside activities. It led to a detrimental influence on students' mental health. The purpose of this study was to investigate the prevalence and risk factors of depression and anxiety among medical students and to provide ideas for the prevention of depression and anxiety in medical students. A cross-sectional survey was conducted among 2,116 medical students at Kunming Medical University from July 8 to July 16, 2020. Participants' demographic and living conditions were collected. Depression and anxiety were measured using the Patient Health Questionnaire 9 and General Anxiety Disorder-7, respectively. Uni- and multivariate logistic regression analyses were performed to detect risk factors associated with depression and anxiety. The prevalence rates of depression and anxiety among medical students were 52.5 and 29.6%, respectively. Depression was more likely to be caused by low grades, lack of physical exercise, drug use, irregular diet, extensive screen time on mobile phones, being greatly affected by the COVID-19 pandemic, and inadaptability to offline courses. Anxiety was more likely to be caused by lack of physical exercise, drug use, irregular diet, and inadaptability to offline courses. Depression and anxiety are highly comorbid. Our study showed predictive factors for depression and anxiety and identified a major mental health burden on medical students during the COVID-19 outbreak. More targeted measures should be taken to improve the mental state of students to reduce the incidence of depression and anxiety.