Answer: You are taking too much magnesium from a supplement, and diarrhea is known side effect of exceeding the Upper Tolerable Intake Level (the "UL") for magnesium when taken as a supplement. Magnesium that occurs naturally in foods does not cause this. Supplements should only be used to help you get to your requirement. If you must take a high amount of magnesium for medical reasons, certain forms are less likely to cause diarrhea than others.
For details see the Dosing and how to take section of our Magnesium Supplements Review. Also see our Top Picksamong products -- covering moderate-dose as well as high-dose magnesium (in the form less likely to cause diarrhea).