A federal appeals court has opened the door to legalising prostitution in California.

The 9th US Circuit Court of Appeals in San Francisco recently allowed a legal challenge to the statewide ban on prostitution to proceed. The ruling overturns a lower court’s decision to toss the case out last year.

During the Thursday hearing, conservative Judge Carlos Bea wondered aloud: “Why should it be illegal to sell something that it’s legal to give away?”

The case was originally filed in 2015 by three unidentified former sex workers, one potential client and the San Francisco-based Erotic Service Provider Legal, Educational and Research Project (ESPLERP).

The plaintiffs argue that the 145-year ban “unfairly deprives consenting adults of the right to private activity, criminalises the discussion of such activity, and unconstitutionally places prohibitions on individuals’ right to freely associate”.

Sex for sale: The truth about prostitution in Britain Show all 2 1 /2 Sex for sale: The truth about prostitution in Britain Sex for sale: The truth about prostitution in Britain In the UK there are some 80,000 sex workers, a figure that is said to include 4,000 women and children trafficked into the country to work as sex slaves Getty Sex for sale: The truth about prostitution in Britain In terms of prostitution, the stories we tend to hear are the most tragic - such as the murders of five prostitutes in Ipswich in 2006; a horrific story, but a quantum leap, from the experiences of most women who sell their bodies for a living Getty

ESPLERP president Maxine Doogan claimed being associated with prostitution today is akin to a “social death”.

“Our hope is to see this bad law struck down, so that consenting adults who choose to be involved in prostitution are simply treated as private citizens again, and are afforded all the privacy and constitutional rights thereof,” she said.

Louis Sirkin, an attorney for the plaintiffs, cited a Supreme Court decision that struck down gay sex bans as evidence for their case. The 2003 ruling, in Lawrence vs. Texas, found that consensual sexual conduct was part of the “personal and private life of the individual”, and protected by the due process liberty right.

Queer Muslim sex worker on her everyday life: 'I'm a science experiment'

The plaintiffs in this case, Mr Sirkin argued, are “voluntary individuals who want to engage in sexual activity”, according to CBS News.

The case revives a long-running argument in which both sides invoke protecting vulnerable sex workers. Proponents of decriminalising sex work argue that an ancient, consensual activity should be allowed and that making it illegal hurts marginalised members of society. Opponents warn that removing criminal penalties would embolden pimps and validate abuse of women.

Numerous civil rights and LGBT advocacy organisations have supported the case, arguing in a court filing that sex between consensual adults should not be illegal. They also argued that gay and transgender people are disproportionately affected by the prohibition because they are more often targeted for prosecution – whether or not they’re actually engaged in sex work – and that women selling sex are arrested more than men buying it.

“We see this is as an important issue both as a matter of liberty and as a matter of equality”, said Amanda Goad, an LGBTQ rights staff attorney for the American Civil Liberties Union of California.

“There’s a huge difference between consensual sex work and exploitative sex trafficking – I think we’re all agreed that sex trafficking is a big problem that shouldn’t be acceptable by any stretch. What we’re saying needs to be decriminalised here is voluntary work”, Ms Goad said, arguing that criminalisation harms sex workers because “you can’t really go to the police when you’re feeling unsafe, you can’t do anything about an exploitative workplace or wage theft”.

The state, meanwhile, argued that the ban did not restrict consensual sex itself, but the sale and purchase of it. Deputy Attorney General Sharon O’Grady, the attorney for the state, argued that banning commercial sex helped protect against violence, drug use, and trafficking as well.

“The state is not telling anyone who they can sleep with,” Ms O’Grady said.

Backing California’s argument are a number of anti-sex trafficking organisations that argued in a court filing that “prostitution is inherently harmful and is integrally connected to sex trafficking, drugs, brutal physical violence, rape, and murder”. The filing warns that legalising prostitution would empower pimps and traffickers.

Lisa Thompson of the National Centre on Sexual Exploitation, which joined that filing, called prostitution a “raw manifestation of male sexual entitlement”.

“To the extent that this is permitted by law, they enshrine a right to buy human beings”, Ms Thompson argue in an interview, warning of “gender-based sexual exploitation” that would allow men to prey on women who have “acute vulnerabilities”.

California outlawed prostitution in 1872, with a law defining “every common prostitute” as a “vagrant”. Current California law defines prostitution as a misdemeanour punishable by up to six months in jail or a $1,000 fine. A 2008 ballot measure to decriminalise prostitution in San Francisco failed by almost 60 per cent of the vote.

But the state has already removed criminal penalties for juvenile sex workers, passing a law that forbids police officers from arresting minors for prostitution or soliciting with intent. Backers argued that the law would stop penalising young victims who are exploited by traffickers, but law enforcement opponents warned it would make it more difficult to separate sex workers from their pimps and get them help.