Non-drinkable tap water is mostly due to water not being available 24x7x365. If a water system is turned off even momentarily, the pressure drops to zero, and sewage and groundwater seep into the water pipes, making it unsafe to drink.
Countries with unreliable power grids usually don't have drinkable tap water for that reason.
It can also be because the water isn't treated (ie. it is just rainwater in the pipes). Water treatment actually isn't very expensive though - collecting the water and distributing the water are by far the biggest costs.