As unappetizing as it may sound, it is generally much easier to treat wastewater to a drinkable standard than treat a low quality surface water or ground water source. Wastewater is mostly water anyway, generally with lower solids than a muddy river source, which is what costs real money to get rid of. Wastewater also has good energy sources for bacteria to eat up and remove the complicated things to get rid of, like nitrogen and phosphorus. The only thing you can't get rid of well in wastewater is salts. Run the wastewater through membrane filters capable of removing all viruses and you generally have something that is drinkable, though there is typically an advanced oxidation step as well to get rid of any lingering organic substances. In Singapore, they are running their domestic supply on 15% reclaimed wastewater, as it was far cheaper than desalination to meet their needs.