In your example, the lottery ticket is a regulated product, because lottery itself is a regulated activity. You need proper qualifications to run a lottery. Same with cigarettes, alcohol, medical operations, vehicles, etc.
Sex between adults is not a regulated activity. Anybody can do it and the government has no authority in people's sex lives.
By the way, the problem is not exactly with the fact that buying is illegal. The problem is that this pushes the legal half into clandestinity, where they are at higher risk of violence. If there was no ill effect on the seller, it would not invalidate the law.
Even people who don't like prostitution should be afraid of this law. If they can ban prostitution by simply claiming it is harmful to society, what's stopping them from doing the same with free sex next?