Answer is pretty straightforward
Firstly we need to know how does the atom of Magnesium(Mg) looks like here
It has 2 electrons in first orbit , 8 electrons in second orbit ,
and 2 electrons in third orbit .
So it needs to get rid of 2 electrons to reach nearest stable configuration which is 2,8 .
Clearly these two electrons are not just going to pop out.There needs to be some energy to take those electrons out which you to form an intuition can be considered attraction from other negatively
charged atoms like chlorine
Anyway so in summary this energy is called Ionisation Enthalpy
For any cation X(cations are elements which tends to lose electrons)
X is atom or atoms of cationic element
Energy is ionisation enthalpy required
In our case on right side applying some energy on Mg it loses two electrons so finally on right side two electrons are separated.
Hopefully that helps
If you have any further queries