Sodium and Magnesium are both metals, when they are solid they form a metallic lattice held together by the electrostatic force of attractive between the positive metal ions, and the negative delocalised electrons. Both elements are in period 3 of the periodic table, this tells us that they both have the same number of energy levels. and so their nuclei are the same distance away from the delocalised electrons. However, Magnesium is in group 2 and Sodium is group 1, this means that Mg cations have a +2 charge and Na cations have a +1 charge. The higher charge on the Mg2+ ion means there is a stronger electrostatic force of attraction between the ions and the delocalised electrons in the metal lattice, this means that more energy is required to overcome this attraction and so Magnesium has a higher melting point than Sodium.