Can anyone take magnesium supplements? And why do we need it?

Most can. Magnesium is freely excreted by the kidneys, so if you have normal renal function it won't bother you. But if you have kidney disease your levels could increase with supplements. Also magnesium supplements aren't needed unless your level is low, which could also cause low potassium levels.
No need. Magnesium is an essential element for metabolic activities. Regular healthy diet should provide daily requirements. Certain medical conditions and medications can make us loose magnesium and so may need additional supplementation. Doctors treating those conditions and prescribing those medications usually monitor magnesium levels and prescribe magnesium as needed. Please check with your doctor.