An atom or ion with a full outer shell is more stable than one with an incomplete outer shell. In the outer shells of calcium and magnesium there are two electrons. It doesn't take as much energy to remove these two electrons to form a full outer shell than to add six electron to the same end.