All the info is in the game. When you are imprisoned, factions that you have decent to high rep with will come to rescue you after a short time. You can speed this along by resting. It is possible that you have no factions with good reputation. A rescue attempt also doesn't guarantee you'll escape as it's just a couple people showing up that will let you out of the cell and aid in your escape.
If you don't like this there are customization options available to you in the game where you can set prison mode to easy so someone will always come to rescue you regardless of reputation and the rescue is guaranteed. I think if you do it this way it's the shopkeeper from the start of the run and she will ask for compensation for rescuing you.
This game (on standard settings) seems to be intended to be a rogue-like adventure where you can fail. If you are stuck in prison and can't get out it might be time to quit your play through and start a new one if you so choose, or load from an earlier point using the codes provided. The game is super customizable and you can change it to be or more or less difficult in areas of your choosing.