ill put it simply like this:
1st ionization energy:
Mg according to periodic trends is more to the right therefore the ionization energy is higher than Na.
2nd ionization energy:
Now since you took an electron out of each Mg and Na, Na is at Ne and Mg is at Na position (number of electrons wise). So since Na is very stable (it has the same number of electrons as Ne) the 2nd ionization energy of Na is waaaaay higher than the 2nd ionization energy of Mg because Mg can go another round of ionization before it becomes stable and have the same electron configuration as a noble gas...