The magnesium ion is in group two of the periodic table, whereas sodium is in group one. This means that magnesium has one more proton than the sodium ion, so it has a more positive core. Both ions have the same electron configuration, so the magnesium ion has more protons pulling the same amount of electrons as the sodium ion. This means that the more positive nucleus attracts magnesium's outer shell negative electrons, much more strongly than the sodium nucleus, hence magnesiums smaller ionic radius.