Petrol stations which do not form part of an official (signposted) service area are not obliged to provide free toilet facilities, but they usually choose to as it keeps customers coming in and prevents customers asking for access to the staff toilet.
Historically toilets were kept separate from the rest of the service area, on the assumption that people would stop to use the restaurant anyway. As this turned out not to be the case, the separate toilets had the unfortunate tendency to keep customers away from the profitable part of the building. As a result, building design changed and the toilets are now usually found at the very back of the building, behind all the main sale points.
Despite a number of attempts to introduce feedback and cleanliness programmes, until the mid-2000s complaints about the quality of the facilities provided were still rife. Large service areas have since moved away from small and grotty facilities and focused on large areas with bright lighting. Nationally, visitor satisfaction has increased but issues have not been eradicated.
Unlike petrol stations, small diners generally don't like people visiting to use the toilets without making a purchase. Famously, Little Chef was the exception to this rule, and the EG Group services that replaced them usually have publicly accessible toilets. Where there is a small diner forming part of an official (signposted) service area, visitors only wishing to use the toilets would be expected to visit the petrol station instead.
All of the services listed on this site are supposed to have free toilet facilities, with a couple of exceptions that are explained on their page.
Issues with service station toilet facilities should be directed to the operator. Highway authorities have ruled out regulating them.