Cancer patients often suffer from severe stress reactions psychologically, such as anxiety and depression. Prostate cancer (PC) is one of the common cancer types, with most patients diagnosed at advanced stages that cannot be treated by radical surgery and which are accompanied by complications such as bodily pain and bone metastasis. Therefore, attention should be given to the mental health status of PC patients as well as physical adverse events in the course of clinical treatment. To analyze the risk factors leading to anxiety and depression in PC patients after castration and build a risk prediction model. A retrospective analysis was performed on the data of 120 PC cases treated in Xi'an People's Hospital between January 2019 and January 2022. The patient cohort was divided into a training group (n = 84) and a validation group (n = 36) at a ratio of 7:3. The patients' anxiety symptoms and depression levels were assessed 2 wk after surgery with the Self-Rating Anxiety Scale (SAS) and the Self-rating Depression Scale (SDS), respectively. Logistic regression was used to analyze the risk factors affecting negative mood, and a risk prediction model was constructed. In the training group, 35 patients and 37 patients had an SAS score and an SDS score greater than or equal to 50, respectively. Based on the scores, we further subclassified patients into two groups: a bad mood group (n = 35) and an emotional stability group (n = 49). Multivariate logistic regression analysis showed that marital status, castration scheme, and postoperative Visual Analogue Scale (VAS) score were independent risk factors affecting a patient's bad mood (P < 0.05). In the training and validation groups, patients with adverse emotions exhibited significantly higher risk scores than emotionally stable patients (P < 0.0001). The area under the curve (AUC) of the risk prediction model for predicting bad mood in the training group was 0.743, the specificity was 70.96%, and the sensitivity was 66.03%, while in the validation group, the AUC, specificity, and sensitivity were 0.755, 66.67%, and 76.19%, respectively. The Hosmer-Lemeshow test showed a χ2 of 4.2856, a P value of 0.830, and a C-index of 0.773 (0.692-0.854). The calibration curve revealed that the predicted curve was basically consistent with the actual curve, and the calibration curve showed that the prediction model had good discrimination and accuracy. Decision curve analysis showed that the model had a high net profit. In PC patients, marital status, castration scheme, and postoperative pain (VAS) score are important factors affecting postoperative anxiety and depression. The logistic regression model can be used to successfully predict the risk of adverse psychological emotions.