Ionization energy is the energy liberated when electron is removed from the isolated gaseous atom
Magnesium has higher ionization energy than sodium .
The more stable electronic configuration has a greater ionization energy.
Sodium outer electronic configuration is while for magnesium it is . As magnesium has a completely filled orbital , it's ionization energy is greater than sodium. (half filled and full filled orbitals are more stable)