The Lewis dot structure of Mg²⁺ is shown in the picture attached.
In Mg atom, the outermost orbit has 2 electrons.
The atom has the ability to lose its 2 electrons to become Mg²⁺
The Mg²⁺ ion have completed its vacancy in the second orbit having 8 electrons.
Therefore, the valency of Mg becomes 2+ as it loses its electron.