Prostitution is illegal in Thailand, but the law is rarely applied to the industry as a whole, and it is widely tolerated. That gap between the law and what you see is the main thing to understand.
What the law says
The Prevention and Suppression of Prostitution Act of 1996 bans prostitution, along with procuring, running a brothel and soliciting in public. The harshest penalties are reserved for trafficking and for anything involving children. Enforcement against ordinary adult sex work has been patchy for decades.
How the industry operates
Most of it works under other labels: bars, massage shops, karaoke venues and similar businesses registered as entertainment. Raids happen, often tied to campaigns, and are followed by a return to normal. Sex workers and advocacy groups have long argued for decriminalisation, because the current system leaves workers without legal protection while still criminalising them.
Risks for visitors
Illegal but tolerated means the rules are unclear and the risks fall on whoever is in the weakest position. Visitors face theft, overcharging and drink spiking in some tourist areas, and being in the wrong place during a raid. Anything involving someone under 18 carries severe penalties for the buyer, including for foreigners.
How it compares
England and Wales allow paying for sex between consenting adults, with limits on brothels and public soliciting. See the UK law guide, and the country by country guide for the rest.