There is no federal ban on prostitution in Mexico, so the answer depends on the state and often on the city. Selling sex between adults is not a crime in many places, but the rules around it differ widely and are inconsistently applied.
Zones of tolerance
Many cities have designated areas, known as zonas de tolerancia, where it is allowed and sometimes regulated, with registration and health checks. Outside those zones, street soliciting and running a venue can be offences under local rules. What is allowed in one state may be an offence a few hours away.
What is a crime everywhere
Pimping and profiting from other people’s prostitution are crimes under the law, and so is human trafficking. Anything involving someone under 18 is a serious offence, and Mexico has taken action against child sexual exploitation in tourist areas.
The reality
Regulation is patchy and exploitation is a documented problem, including trafficking. Some of the places that look like normal businesses are not, and visitors who go looking can end up in situations that are unsafe for them and for the people working there. Robbery and drink spiking are reported in some tourist areas.
How it compares
The position in England and Wales is national and clearer: paying for sex between consenting adults is legal, and brothel keeping and public soliciting are not. Read the UK law guide and the country by country guide.