I always saved before doing stuff that might tick off people. I believe some jails have a lockpick under a pillow, or something. I don't know if there are some you must wait out to be released. A method for getting Commander Ralph out of his room if he locks himself in involves dropping a teleporter stone in the cell beforehand, so I would assume there is no easy way to escape otherwise.