Historians have often speculated that prostitution has existed since the beginning of civilisation. It is thousands of years old. In a future where prostitution is a thing of the past, and preferably without any world-ending consequences, how would this be done. This future is quite bleak but I'd like to avoid genocide and enormous STD plagues if possible.
Whenever a thing or service is sold it is subject to the laws of supply and demand.
A service is sold because there's a demand for it.
Eliminate the demand.
There's two ways to do this. a) Completely destroy the human sex drive or b) make sex so available that there's no reason to buy it.
B can be achieved in a number of distasteful dystopian ways (all homes come with a free pleasure bot, it's illegal to refuse any offer of sex, and so on and so forth). A can be achieved through anything from environmental controls, to behavioral modification, to genetic manipulation, to removal of glands/sexual organs at a young age.
All of these are not world-ending, but none seem all that fun...
Promote 1970s style of "free love." If sex is readily available to anyone, they won't need to pay for it.
If you could walk up to anyone and ask if they want to have sex and have them say, essentially, [looking at watch]"I don't have anything else to do for the next hour. So, sure." then there wouldn't be as much pent up desire for sex.
The idea is to devalue it. Putting government or societal restrictions on it works no better than prohibition or the war on drugs. A prohibition actually raises the value of it since it is something to be sought after and turns people into criminals. It also funds or creates organized crime. Prohibition was great for the Mafia and the war on drugs is great for the Cartels.
It's not exactly a deterrent, but decoupling resources from labor might do the trick, and as we march ever-toward the automation apocalypse, it might even become possible. If everyone is simply allocated the resources they need to live and do their thing by society just for being there, there's no motivation to engage in prostitution (or any other sort of paid labor.) Though that sounds pretty nice, you could write such a world as bleak, full of people living out a self-imposed solitary confinement because they aren't required to get along with each other to make a living. The last generation of humanity, all gone mad with skin hunger, sucking desperately on a mechanical teat affixed to a boob tube. While shitposting, no doubt.
I will focus on multiple ways a society or part of a population loose the interest or ability to sustain prostitution as a field of work. Some might not fit your particular setting, but might help others with the same question.
A: Polygamy is common, and there is no social incentive to pay for sex. You could look into societies alike to Huxley's Brave New World, where children are raised by the community, and sexual exploration is a thing of the mundane.
B: The part of society relevant to your setting lives in utopian conditions, where money or personal belongings are a thing of the past. There is no financial incentive to take money in exchange for anything, including sex.
C: Your question states to avoid STDs. If the relevant population is misinformed about the dangers of prostitution (e.g. through religion or government programs) and has an enormously heightened fear of catching STDs from sex workers, social stigmas could increase to a point whereprostitution is basically nonexistent. Couple this with A or B maybe.
D: To focus more on the "bleak future" mentioned in the question and to give a counterpoint to B; The relevant population lives in dystopian conditions where personal belongings and privacy are a thing of the past. Because prostitution is a common business where poor living conditions prevail, you'll need total control of the citizens' lifes (similar to what
Demigan mentioned in their answer). There is no need to go full 1984/concentration camp on this topic though; you can look at the living conditions in chinese factories (as outlined in this answer to a question regarding prison life) to get an idea of what's already sad reality. Government regulation for who's allowed to have children, combined with the absence of reliable contraceptives and privacy could make prostitution (and sex in general) too risky. Note though that even in the aforementioned Nazi concentration camps, inmates had sex and raised children without being noticed by the guards. Depending on the level of technology in your world, this could be made near impossible though. Think implanted medical monitors that would alarm government officials when noticing a rise in certain hormone levels, or similar hard to circumvent measures. In the world of Æon FLux ... (spoiler)
...the government controlled all food distribution. All people were sterile, but didn't know, and when a couple checked with a doctor wether they were pregnant, the doctors acctually injected hormones to make their bodies show signs of pregnancy. Fertilized eggs from a sperm/egg bank were implanted to allow for an actual pregnancy to occur. If I'm not mistaken, this partial plot summary is correct. I remember government distibuting food containing a 100% effective contraceptive too, but am not sure wether it was contained in this plot. Feel free to edit.
You could have a similar system in place, maybe with a sexual depressant in addition to the food contents mentioned in the spoiler. Government would have full control over who gets to reproduce, and there would be little use for prostitution.
There is only one way to eliminate it completely a complete lack of scarcity, (which is probably impossible) only in a post-scarcity society would it not occur. As long as humans want sex and humans want things, prostitution will exist.
If you are trying to just minimize it you may want to adjust your question.
Mega-big-brother. For everyone's safety, they are continuously tracked and monitored by large (autonomous) computer centers. Any lawbreaking is punished, and prostitution has been made (or kept) illegal.
That's the only method I can think of that didn't instantly destroy anyone's normal ability to have sex.
Make reproduction state controlled and then make it so children never experience puberty through hormone therapy or direct gen editing. No more sex means no more prostitution.
People can be artificially grown in artificial wombs and the DNA is doctored so that there is good genetic diversity and no need for sexual reproduction.