Why are bathrooms on the outside of older gas stations? It is certainly not for convenience to the user when you have to come inside for the key. Is it to discourage shoplifting, perhaps?
Older stations may have started out as “full service” stations. In those cases, there’s a small sales counter / waiting area, with maybe a vending machine and a map rack, with access to the rest of the interior behind a sign that says “Due to insurance regulations, no customers are permitted beyond this point”. The first step in phasing out full service was bricking up one or more of the service bay doors and stacking soda there for sale. Eventually the interior gets converted to more of a retail-type establishment, but it isn’t worth their while to build new bathrooms inside, with all the plumbing that entails.
Generally, if it isn’t broken and won’t make them more money to change it, it stays the way it is. As another example, in New Jersey you may come across a gas station with a green spotlight and wonder why it is there. The answer is that during the energy crisis, NJ stations were required to display flags (daytime) or lights (nighttime) of green / yellow / red to indicate availability of fuel.
In the old days, stations all had the rest rooms on the outside and they were unlocked during business hours and sometimes after as a public service. I believe people enjoyed the privacy, especially women, of not having to greet the grease people inside. Having to come inside for a key developed when vandalism and theft got out of hand. There are no “old” gas stations where I live. The restrooms are inside by law as a part of the food service offered. Businesses want people to come in and buy “stuff” because “stuff” is more profitable sometimes than the gas. (The product cost for 99¢ retail coffee is no where close to the relative cost of gas.) I have seen complete stations and tanks pulled up and replaced in as little as five years here. All the old stations had steel tanks, which eventually leaked. Everything has been or is being replaced with fiberglass reinforced tanks not subject to rust. When you are building all new, you design it for the present code and culture.
In days of old gas stations were not the mini marts of today; but serious automotive service centers where they worked on cars. I recall the one in my home town only had an old style Coke machine and a couple of boxes of candy bars that never changed over the years. We kids would come in and get our drinks and candy and attempt to hang around while they worked on the cars because 1) it was cool and 2) we didn’t have the internet (or even cable TV) to keep us entertained. We would then take advanatge of the free air for our bike tires and enjoy the show of watching them do things like taking cutting torches to shocks and listening to mechanics swear when they banged up thier knuckles.
One way to discourage this sort of activity was to keep the bathrooms locked so that when you had to go you had to ask the grumpy old owner (Earl) or one of his grease monkeys for a key and more likely than not they would deny you access and tell you to go home to your mother and quite bothering them.
Given the condition people left those old bathrooms in, would you really want them inside the building?
Seriously, I remember the time that I stayed in a gas station bathroom for 15 minutes on a Saturday night (I was on a bike; a cold front had come in, and I was putting on every piece of cloting in my saddlebags.) Guys were continually knocking on the door and cussing, but there were only two or three outside when I came out. The sidewalk was soaked. No gas station owner would have wanted this inside.
Besides that, a store would benefit from having the bathrooms inside, since people would have to go past the cokes and candy to reach the bathroom. As Terry Kennedy pointed out, the inside of an old gas station was meant as a small office and waiting area and wasn’t meant to generate revenue.
Somewhat on-topic: it seems like before the 1980s, businesses with bathrooms that were only accessible from outdoors were far more common. I remember some smaller fast food chains had such bathrooms, such as Red Barn.
Quite a few food places had the restrooms only accessible from outdoor entrances too. Tastee Freeze and Arbys both were like this.