As far as I can tell (doesn't appear to be any other options in game), the only thing you can do is trade them back to the civilization they belong too. There does not seem to be a limit on how long you can hold them, however if you are playing against AI opponents, they will usually ask for them back pretty quickly and give some decent stuff in trade.
My strategy is to always run a couple counterspies in my capital, or to keep all my districts adjacent so I only need 1 counterspy, and then let them attempt to spy on me. Then when I capture the spies that are eventually sent, I get free stuff, give them their spy back, and repeat.