You have to get yourself thrown into the dungeon by the guards. For me, the easiest way to do this is by setting up shop, and checking both of the "special offers," as this will most likely lead to the guards coming for you. You have to select either "surrender" or "cooperate," depending on which options you have, and then select "dungeon" when he asks you where you want to go to server your time. Gray will appear to release you.