They're usually in a far-off corner which makes them hard to see from the register. Locking them, in theory, reduces shoplifting, keeps someone from clogging the toilet, vandalizing, etc.
It isn't allowed to install cameras, so they do that to 'inspect' the person entering. I doubt if you look like a heroin addict, they would hand it to you. Half the people in gas stations barely speak English, imagine them having to fill out a police report over the dead body in their bathroom.