Why does soap scum form in hard water that contains #Mg^(2+)# ions when a sodium stearate soap is used?
Because magnesium and calcium stearates are insoluble beasts.
Sodium stearates typically form insoluble calcium and magnesium salts, which you have to scrub off in the bath or toilet. Think about this the next time you clean the bathroom, and think about the cleaning agent you are using (a cheap alternative is vinegar! why would this be effective?).