Both sodium and magnesium have metallic bonding between atoms. Outer electrons become delocalised and float freely between the positive ions. The positive ions attract the negatively charged electrons so the bond is very strong.Magnesium has a higher melting point because magnesium ions are Mg2+ and sodium is Na+. Magnesium ions have a stronger positive charge so the attraction to the delocalised electrons is stronger. There are also more delocalised electrons in magnesium than there is in sodium. This makes the metallic bonding in magnesium stronger so more energy is required to break it.