Magnesium is not stable before bonding. It is in group two so it has two valence electrons. An element is only stable with eight valence electrons. Oxygen is not stable because it is in group sixteen meaning it has six valence electrons. It does not have eight so it is not stable.