Prostitution is often called "the world's oldest profession." Although rarely found in rural settings, there have been women selling their bodies for money in the relative anonymity of cities for probably as long as there have been cities. Mary Magdalene, who appears in the New Testament, is generally assumed to have been a prostitute (though the Bible is a bit vague on the topic).
In the early Middle Ages, after the breakdown of Roman urban civilization, there is very little sign of prostitution, probably because the culture was so overwhelmingly rural. However, when medieval cities began to grow in the eleventh century, prostitution grew with them.
The organized church of course frowned on it, but many a city council, deciding it was better to regulate the practice than to drive it underground, established municipal brothels. In late medieval cities, young women (generally from the countryside) who found no other way to support themselves might go into a brothel.
The house was supposed to be kept clean and free of disease and the prostitutes properly housed and fed. In many cities the women would be regularly inspected to make sure they did not have infections. (A lot of what we think of as STDs have New World origins, so there were fewer diseases to fear, and AIDS was centuries in the future.) As deplorable as modern feminists rightly find prostitution, at least in an organized medieval brothel the women did not have to worry about maltreatment from their pimps.
Many "Magdalene houses" were founded to urge women to "give up their life of sin" and come away from the brothel. The assumption was then that women had gone into the profession out of unrestrained lust, even though now it sure looks more like economic desperation. Churches sponsored these Magdalene houses, which in practice provided a useful half-way house for young women who had saved up enough from their "life of sin" that they wanted to separate themselves from it and, with luck, get married with their savings as dowry.
Saint Nicholas societies provided money for dowries to poor-but-honest working girls so that they could get decently married without having to sell themselves. These were particularly common in late medieval/Renaissance Italy, where dowries were essentially obligatory.
Often municipal brothels were connected with the municipal bath houses. People would bathe, and while all warm and naked would start to have other thoughts as well, which could be satisfied right nearby. In modern Britain brothels are still sometimes referred to as "stews," because of their association with bath houses.
In fact, when the Black Death showed up in western Europe in the fourteenth century, one of the immediate results was closing down the municipal bath houses, because it was assumed (correctly) that disease would spread easily there. However, the municipal brothels just became even more closely regulated. City councils recognized that people will, if frightened of dying, give up bathing, but they won't give up sex.
Incidentally, until the fourteenth century most people had believed in the weekly bath (on which see more here). After that, aristocrats, who did not get all dirty and sweaty in their daily activities, prided themselves on not bathing. Sponge baths and hand-washing were about the limit. (Peasants, not having much choice, continued bathing if they could.)
Medieval municipal brothels continued until the sixteenth century, when the religious ferment of the Reformation finally led to their demise.