What is the precipitate of this reaction of magnesium?
With $\ce{(NH4)2HPO4}$, $\ce{Mg^2+}$ forms a white, crystalline precipitate of magnesium ammonium phosphate hexahydrate:

$$\ce{Mg^2+ + HPO4^2- + NH4^+ + OH- + 5H2O \rightleftharpoons Mg(NH4)PO4 \cdot 6H2O\downarrow}$$

This is a very sensitive test for $\ce{Mg^2+}$; however, calcium, strontium, barium and other heavy metal ions also form precipitates of phosphates under these conditions. $\ce{Mg(NH4)PO4 \cdot 6H2O}$ can be distinguished by the form of its crystals when they are examined under a microscope. It forms rhombic crystals with prismatic shape, and is less microcrystalline than other earth alkali metal phosphates (sources: 1, 2).