The fact that most Dungeons & Dragons campaigns are loosely based upon Medieval history and culture is both a benefit and a liability.
The benefit can be found in relying upon player expectations in order to enhance suspension of disbelief; since most players aren’t medievalists (which is a pity), telling them that there are knights and castles and dragons around is enough to get the game rolling, and the players will mentally fill in missing details as play progresses.
The liability emerges from that same circumstance. Since dungeon masters (DMs) and players – including professional designers - typically don’t know a great deal about Medieval daily life, they tend to place a Medieval veneer on 21st Century social systems when designing communities for D&D settings. While such anachronisms don’t affect game mechanics, it does forsake an opportunity for a DM to provide a more accurate picture of how things were, thereby providing a more immersive experience for players.
One aspect of D&D setting design that routinely gets the “veneer treatment” is law enforcement. Typically, the city or town watch is the staple of public safety, sometimes supplemented with a peasant militia, providing what basically amounts to a modern police force equipped with chainmail. Historically, the closest pre-Renaissance society gets to such a thing is the office of wait, or night watchman, who shouts out the time on the hour each night and keeps an eye out for trouble or fire, but these fellows weren’t organized into bands responsible for public safety until the 15th Century.