Soap was invented a long time ago - 2800 BC and the Romans made quite a bit of it. However it used lye so you wouldn't want to use it often.
The sanitation of Roman cities should have been pretty good by historical standards. Batthouses were common in the empire and people frequently visited them. Romans also had toilets with running water below them to take the waste away so in that regard they would have done much better than other societies.
The sewer system or lack thereof was the biggest sanitation issue for most historical cities. Back in the day it was difficult to create a sewer system since you need to minimize the slope at which the waste flows or else you have to do too much digging. Until Newton and Leibniz came around in the 1700s we didn't have calculus so you couldn't optimize a function mathematically and instead had to experimentally test it out. But, people didn't test things the way we do today - the scientific method was only formalized relatively recently as well. So this was more difficult to invent that you might think, and the invention has been lost several times over history.
Then once you figure out the minimum angle you have to discover a technique to dig at that angle. The simplest is to take two sticks and insert them into the ground, then tie a string between them that lies right on the ground. Then you can put the sticks this anywhere to see how deep you need to dig.
Since you mentioned 1500-1800, I'll mention that medieval London did NOT have a sewer system so people dumped their waste in the River Thames. Which is also where they got their drinking water.
I'd like to opt out of lemvotes