I would go the opposite route to most of these answers (if possible): Instead of making sure a spellcaster with spell slots remaining cannot use them, I would make sure the spellcaster does not have any spell slots remaining (then prevent long rests as you indicated in your question):
- Gather enough/high enough level guards/casters that the character would not be able to overcome even with all of their spell slots
- Have a Paladin cast "Zone of Truth"
- Ask them how many spells they can cast of each level before their next long rest (threatening them with removal of hands/tongue if they refuse to answer--Edit: oranswer—or any other answer to this question--deathquestion—death, gagging + tying hands, herbal tea, whatever). Once they answer, you know its true, and proceed to next step. If they don't answer, follow through on your threat (of whatever severity you chose).
- Based on comments: For PC wizards/spellcasters who have been captured, making and following through on a severe threat may feel pretty bad for the player. Stick to lesser threats if you anticipate players may ever end up in this situation. NPCs can always still choose to use up their spell slots: it would make for a much more comfortable jail stay than even the least of the other answers.
- Force them to use all of their remaining spell slots in a verifiable way, while monitoring them closely for shenanigans
- For extra confirmation, cast Zone of Truth again and ask them if they have any remaining spell slots. Repeat 4 and 5 until you get a verifiable "No"
- Disband the high level guards
- Prevent them from taking a long rest for the remainder of their stay
- Rest easy
One advantage of this approach is that it more closely parallels how you'd treat other classes: Would you take a fighter's weapons away, or would you let him keep them while tying his hands behind his back for the entire stay? Would you take a rogue's equipment away, or would you leave him his equipment and glue his fingers together?
The sensible answer in all cases is to take away the threat, not try to make it unusable in some way by treating the prisoner unnecessarily cruelly.
The other advantage is that if a traitorous guard wants to help the spellcaster escape by restoring his spellcasting ability, it's not enough to remove a gag or other piece of equipment: they need to help him get a long rest (which takes much longer and should be easy to prevent), so it is also more secure.