While this isn't applicable in all areas, a rule of thumb could be "those who making money with the people which have to use toilets".
Anecdotal example: I'm living in an amusement district of a big German City. There are very few public toilets and most of the few are paid ones. So every weekend the whole district is smelling like a big bowl of piss, except in winter when the frozen pee of multiple weekends accumulate until there is the big pee-melt.
Why not making all those bars, clubs and liqor stores pay for the maintanance of free public toilets?
In the US, there's a law that says all places that serve food and aren't on a public street (e.g. a food truck), have to have a public toilet.
At least in my jurisdiction, gas station don't have public toilets because they want to---they have it because since they serve reheated hot dogs, they are required to have a toilet.
To be honest, I can name only 2 places where the toilets are paid in Russia - train and some bus stations and there are paid toilets near metro stations in Moscow.
Does anyone know what public toilets cost (in construction and maintenance)?
For the private parts of a city (eg. apartments), they usually include toilets, and you expect your guest to use them instead of shitting in your kitchen or living room.
Similarly, as _owner_ of a share of the common parts of your city, you have the choice of providing public toilets, so that guests, visitors, or just citizen far from their home can be expected to use them, instead of shitting in the public space, thus degrading the bacteriological common space (feces can transmit some bad illnesses https://en.wikipedia.org/wiki/Fecal–oral_route ).
It can be paid for with land value taxes: https://en.wikipedia.org/wiki/Land_value_tax
Indeed, it effectively used to be - they typically are and were paid for with property taxes, which is a proxy for LVT. The political decisions to decline property tax revenue is the reason why many closed.
Landlords' entitlement to an ever larger stream of rental income that includes the value of land which they had no hand in creating or making valuable is largely why state/city budgets are in such a mess, why the 1% steadily gets richer and why property values keep going up.
There are two independent solutions for this: Many countries, like Singapore, have the government directly own public toilets.
In other places, like some states of Germany, the government instead pays restaurants and shops to open their toilets to the public.