In order to break into the prison where Rioichi is being kept, you're going to need a disguise. You need to pickpocket three guards around the hub area until you get three pieces of Samurai armor. The first guard is by Rioichi's restaurant. The second guard is behind the geisha house. The third, and final, guard is in the northwest corner of the map.
With the full costume now, you can head over to the entrance of the prison. You can put the disguise on by pressing the L2 button, as well as take it off with the same button. You do not have access to your old moves, but you can strike with your shield. You also move very slowly and cannot jump. Just walk up to the guard in front of the entrance and after some convincing on Sly's part, you're let inside.
Don the Samurai armor and just walk past all the initial set of guards, going to the end of the walkway to spot Rioichi hanging in a cage. Use your costume again to get past the two guards on the left, but don't go straight, instead going left and crawling through the crawlspace to find a Secret Sly Mask.
Go back and through the next crawlspace to come to an area with a bunch of guards sitting around a table. You need to crawl underneath the table to get to the other side. Wait until the first guard falls asleep, then jump to the raised section of the walkway, then use the costume to sneak past the second and third guards.
In the next section, dragon statues will pop up and breathe fire on the path you need to use. The Samurai armor will allow you to walk past these unharmed, but the swinging axes will still damage you. Make your way past the first set, then jump to the second walkway. Sneak your way past the next set of guards, jumping across the gap when the second one falls asleep. Grab the rope at the end to slide down to the next area.
Climb up, then shimmy across and climb up again to get to the top. Instead of going through the doorway, jump over to the wooden platform to your right and crawl through to find another Secret Sly Mask. Go back and through the doorway and to the room with a big locked gate. Use your costume to sneak to the guard on the other side of the room and pickpocket the key, then unlock the gate.
In this final stretch, as soon as you step on the circle, the bridge will collapse and giant dragon statues will appear. These statues will spit flaming projectiles at you and you need to reflect them back using the Samurai armor. Hold Square until the projectile is close, then let go to reflect it back. Keep doing this until you get to the end, then jump up to the cage to rescue Rioichi.