Introduction Previous studies investigating the relationship between obesity and cognition as well as gender differences in these relationships reported equivocal results. Here, we examined age, years of education, schizophrenia, and gender differences which might affect the relationship between obesity and cognition. Methods 1012 healthy controls and 707 participants with schizophrenia were recruited. Information on body mass index (BMI) was obtained and a neurocognitive battery was administered. Structural equation modeling (SEM) was performed to examine the relationship between BMI, schizophrenia, cognition and its covariates. Results No significant direct effect of BMI on cognition was found when cognition was regressed on age, years of education, diagnosis of schizophrenia and BMI. Instead, two SEM models indicated that indirect effects between BMI and cognition exist. The indirect effect of BMI on cognition through schizophrenia was present in both genders, while the indirect effect of cognition on BMI through schizophrenia was only found in females. BMI affecting cognition through age, years of education and schizophrenia appears to be the most plausible model that explains the data. This indirect effect was larger in females and was masked by diagnosis of schizophrenia. Conclusion With increased rates of obesity in schizophrenia, it is important to highlight the potentially deleterious effect of obesity on cognition. BMI could be used as a candidate risk marker to identify people at higher risk of cognitive deficits, and as an intervention target for modifications of cognitive outcomes.