Prostitution is attested to in the some of the oldest examples of writing - almost certainly it predates that, if not necessarily as a dedicated profession, at least as a part-time job.
The push to make prostitution illegal springs largely from the Protestant Reformation. Traditionally, Catholicism regarded prostitution as a 'lesser evil' than masturbation; Protestantism generally regards prostitution as worse than masturbation.
The largely Protestant push for alcohol prohibition in the USA was accompanied by a push to make prostitution illegal as well. Unlike Prohibition, the criminalization of sex work has remained in the vast majority of the US.