It is because detergents form lot of lather even with hard water.
Hard water contains Ca2+ and Mg2+ ions which react with soap to form insoluble salts of calcium and magnesium called scum and soap goes waste. Detergents do not form insoluble compounds with Ca2+ and Mg2+ ions, therefore, these are more effective.