The answer: Have a good DM that makes sure that the story unfolding has elements that are fun for each of the players.
D&D in an RPG - a role playing game. Characters play a role in a story. The DM and players should be working together to make a fun game for everyone.
If your PCs end up in a jail cell and escape without gear, as a DM you need to make sure there are opportunities for each PC to do something useful until they can get back to full/good strength. You can't force the PCs to take advantage of the opportunities, and it is reasonable to have them figure out how to get to the opportunities, but they should be there to be found and not be too hard to find.
If you're an artificer without his tools, a wizard without his spellbook, a fighter without weapons, etc... and the DM took them away - and the DM leaves you trapped without any chance of having something fun to do - it is a good time to make some suggestions to the DM. If they don't listen ... well ... evaluate whether that is the right game for you.