Don't you loose reputation when you get out of prison, rather than when you are put in? Or does it depend on the circumstances?

If you try to enter Commander Ralph's back room, he can sometimes lock himself in there later in the game, which can be a problem if you need to talk to him to finish a particular quest. One of the solutions for this was to lockpick the door (level 3) after placing a teleporter stone inside the prison cell and the other somewhere on the ground outside the prison. If you then try to enter the back room, get stopped by the guards and agree to go to prison, you can teleport out without loosing reputation, then head back to the prison to recover your stuff.