Some of my dwarves are milling about in a random location (strangely they are pretty close to each other) that is not designated as a meeting area. They are standing around, with "No job" and getting thirsty and hungry but not doing anything about it. Some of the dwarves in my military have reverted to there civilian roles and are among these random dwarves, but other militia members are not. None them are insane or anything like it.
Sounds like you've managed to break connectivity (by removing stairs or ramps, making ramps unusable, or blocking the passage with impassible workshop tiles). You can use station orders to "walk" your military closer and closer to the location of the stranded dwarves to figure out approximately where the break is.
Apparently it's claimed if you keep the hatches over your pits of glory forbidden, pitters MIGHT be able to dump prisoners safely, but I've yet to test this.
Even then, using built cages and levers is the safest, but most pain-staking, method. You would've had to use that method on fliers and thieves anyway.
Try replacing your hatches with bridges. Due to
a bug, dwarves will pit creatures below the bridge even though the bridge itself cannot be opened. I haven't tested it, but the bridge should stop creatures from climbing back up.
You can also use a minecart-shotgun approach to empty cages, though that's rather more complicated.
but why?
Hauling around
magma-filled minecarts will rapidly destroy non-magma-safe wheelbarrows, for one example.