The government and the water regulator broke the law by allowing sewage to be discharged outside of "exceptional circumstances", according to the green watchdog.