Due to surface tension and also hard water contains magnesium and calcium ions and for this detergent is more soluble in hard water than in soft water.thats why detergent is more effective in hard water. point to be noted that soft water contains a small /negligible amount of calcium and magnesium ion