If the metal ions present in a sample of water interact with soap ,a sodium or potassium salt of a fatty acid and resist its dissolution in water then froth/lather is not formed in that sample when soap is used. And the sample of water is called hard water. Normally these ions are Ca2+,Mg2+,.Fe2+/Fe3+ . They may be present as chloride or sulphate or bicarbonate salt,
If the water sample is high in concentration of mineral acid then it can rsist the dissolution of soap in it and that is why the sample acts as hard water, The presence of other ions eg Zn2+, Al3+ etc can cause hardness in water.