Yikes, large amounts of magnesium is what one takes to prepare for a colonoscopy 
My wife and I take about 500mg of magnesium in our daily drinking water bottles - which is excellent to keep one’s digestion system running smoothly without the carbs - but too much magnesium does NOT produce a happy ending.
So glad you’ve managed to identify some of what’s been happening.

For now, as a single working Mom of 2 (with one of those having PKU and requiring an extremely restricted diet,) I try to keep my diet simple. Most of the people who quit Keto that I know quit because it becomes too time consuming or expensive. (Yes, no carb foods are expensive compared to McDonald’s and ramen since someone pointed out how they thought it was weird that it became expensive for me last time lol) The Dr Price’s packets work great for on the go! And, since I have switched back, I’m already feeling a difference. I was able to just complete 1hr of cardio and I feel great! I also had bone broth this morning with added salt so that helps too.