Past obesity can have lasting effects on mental health, study finds