It is very expensive to clean water. Pipes are needed to get cleaned water to homes and sewers are needed to keep waste water away from clean water.
This all costs a lot of money and in poor countries it is difficult to afford.
One of the cheapest ways of dealing with sewage is to use outside pit toilets that are far away from any drinking water. But to get clean water, you need to use pipes.