1. Magnesium may treat anxiety rather than depression. This is analogous to various SSRIs which arguably treat anxiety better than depression[1]. Anxiety and depression are highly comorbid, and both doctors and patients may be bad at differentiating between the symptoms, leading to "I feel better"-type reporting. This might mean that Mg supplementation is a good thing for depressed people because it treats their anxiety, not because it treats their depression. This alternative hypothesis is particularly compelling because magnesium deficiency has a variety of well-understood effects on muscle tension[2] which mimic physical symptoms of anxiety.
2. Magnesium is frequently supplemented concurrently with vitamin D, vitamin K, calcium, and zinc. All of these are known to be active in humans, and vitamin D in particular has been correlated with depression and seasonal affective disorder.
[1] https://slatestarcodex.com/2018/11/07/ssris-an-update/ (see under the bolded "fourth" comment--SSC has a bunch of posts on this topic).
[2] https://en.wikipedia.org/wiki/Magnesium_deficiency#Diagnosis