In countries where paying for toilets is common, if you see a plate with a sign for an amount near the toilet, or a box with a slot for coins in the top, you pay.
You can check the owner/management of the place or ask a regular customer, but basically tourists almost never do.
There might be some scammers, but they will be few and far between. The regulars of the place will ask the management if there are now paid toilets where there never used to be, in which case the management will take action.
As a tourist and one time visitor you just pay, or do not use the toilet.
In some countries you will see a sign that reads (often only in the local language) "free for customers, others pay €0.50" or 'ask for the code at the till'.
Staff in those places are used to foreign visitors who do not understand, they are used to being asked about it, and again, if you do not want to pay for the service, you are free not to use it.
In some countries, under which the Netherlands, all places where you can sit to eat or drink have to have a toilet and usually those are free for customers. But some companies, including McDonalds, have people working the system, asking all people to pay even when they are eating in the restaurant. Not sure whether it is within the law, but those are the places that have to be very careful to collect the money as the highest percentage of people will try to get out of it.
I am Dutch, I travel often in Europe and I am often already happy to see a toilet you have to pay for, as free ones on the streets for women are very rare where I live and travel.