Somatopsychic medical effects are very real. I've gotten very good results with addressing nutritional deficiencies as a first line of defense for issues that often present as mood or mental health issues.
But I don't think you can reasonably conclude that magnesium deficiency is The explanation for increased prevalence of depression in a world that has had so many profound changes.
Things are more crowded. Most people now live in cities instead of rural environments. Among other things, this means people are subjected to much noisier conditions.
We have far, far better information about the world than we used to. The 24/7 news cycle is incredibly stressful, if only because most "news" is bad news.
There are just so very many confounding factors, no, you can't reasonably conclude that this one singular factor is the sole explanation or primary explanation. That's ridiculous.