Purpose: Depression has become a major health concern, particularly in developing countries. This disorder is highly prevalent among certain vulnerable populations, such as prisoners. In Peru, prisons are overcrowded, and the health of prisoners is neglected. Thus, this study aims to estimate the prevalence of depression diagnosed during incarceration in male inmates from all Peruvian prisons and assess its associated factors. Design/methodology/approach: A cross-sectional study was conducted based on the secondary data analysis of the National Census of Prison Population 2016 in Peru. This study included records of prisoners who reported whether they were diagnosed with depression by a health-care professional after admission into the prisons. Descriptive, bivariate and multivariable analyses were performed. Findings: Of the 63,312 prisoners included in this study, 1,007 reported an in-prison diagnosis of depression by a health-care professional, which represents a prevalence of 1.59%. Substance use disorder (adjusted prevalence ratio [aPR] 3.10; 95% confidence interval [CI]: 1.91–5.03), hypertension (aPR 7.20; 95% CI: 6.28–8.24) and previous discrimination (aPR 1.97; 95% CI: 1.62–2.40) were strongly associated with depression, even when adjusting for multiple confounders. Other directly associated variables were, for example, violence during childhood, infrequent visits in prison and diabetes. Originality/value: The right of prisoners to adequate health care is being neglected in Peru. Mental health is a cornerstone of health quality. Acknowledging which factors are associated with depression in prison is important to implement strategies to improve the mental health of prisoners.