Maintaining optimal cognitive function is crucial for middle-aged and older adults. However, the lifecourse mechanisms linking parental religious affiliation to later-life cognition remain insufficiently understood. By integrating religious socialization theory and a lifecourse perspective, and using multiple waves of data from the China Health and Retirement Longitudinal Study, this study employed structural equation modelling to investigate how personal religious affiliation, educational attainment, healthy lifestyles and social participation mediated the lifecourse pathways linking parental religious affiliation to later-life cognition. The results indicated that parental religious affiliation was overall negatively associated with later-life cognitive function. Parental religious affiliation was linked to later-life cognitive function through independent indirect pathways via educational attainment and healthy lifestyles, as well as through serial indirect pathways involving personal religious affiliation. This overall negative association was driven mainly by education-related pathways, while the positive pathways through personal religious affiliation and healthy lifestyles were substantially smaller in magnitude. The pathways involving social participation were not significant. The findings shed light on the lifecourse mechanisms through which family religious background was associated with later-life cognitive function and underscore the importance of education in understanding cognitive inequality in China’s relatively secular context.