Waste sanitation is expensive and it's kind of far down the priority list. Municipal systems typical need operators and maintenance, so it's not a one time expense.
The consequences of inadequate sanitation are somewhat subtle and diffuse. If you stop pooping in the river, that's great, but your river is still nasty if the communities upstream do it. If they clean up their outputs so it's not obviously dirty, it may still be unhealthy.