There is a little more nuance than just your diet. Systems theory is a good example. Some people can have very clean diets but live with other people that are toxic. We tend to respond to others in our environment and that can fuck you up emotionally. For example, if you live with irresponsible roommates, then you may take on the toxic parent role and start to nag. Humans are weird in that they fill roles that are available but cause distress. We see this in the largest system, society, and how the irresponsible nature of central banks causes degenerate and maladaptive habits in people. All these things have an effect on mental health.