With the increasing number of older adults, research on cognitive function has expanded. However, studies examining the mediating effect of depression on the association between complex factors and cognitive function in older adults are still insufficient. Additionally, there is a lack of studies that have investigated these relationships by integrating multiple factors related to the cognitive function of older adults. Therefore, our study investigated the association between the number of family members, self-rated health, depression, and cognitive function in community-dwelling older adults and highlighted the mediating role of depression in these relationships. We used data from 218 older adults aged over 65 collected in a previous study. The independent variables were the number of family members and self-rated health, and the dependent variable was cognitive function measured by the cognitive impairment screening test (CIST). The mediation variable was depression measured by the Patient Health Questionnaire-9 (PHQ-9). Structural equation modeling was used to examine the association between the independent, dependent, and mediation variable. The mean ages of the participants were 81.71 (standard deviation [SD] = 6.00) years, with 198 females (90.83%) and 20 males (9.17%). The structural equation model demonstrated a good model fit (chi-square value = 33.375; degrees of freedom = 24; p-value = 0.0964; RMSEA = 0.042; CFI = 0.970; TLI = 0.956; SRMR = 0.042). Self-rated health and the number of family members were not directly associated with cognitive function; however, depression had significant indirect effects (self-rated health to cognitive function: coefficient = −0.023, p-value = 0.017; number of family members and cognitive function: coefficient = 0.012, p-value = 0.030). Our findings indicated that depression plays a crucial mediating role between self-rated health, number of family members, and cognitive function. The results highlight the need for comprehensive strategies for mental health care to support cognitive health in older adults.