Magnesium metal forms a doubly charged cation. Iodide forms a singly charged anion.
Magnesium comes from Group 2; as a metal it needs to lose 2 electrons to assume a Noble Gas configuration. On the other hand iodine needs to gain 1 electron to assume the xenon configuration. The ion formation reflects this tendency.