Swiss cheese can be avoided by a pathing system, you select a point, then generate a single tunnelling path to that point, and all tunnellers follow that path.
Select a point: You could have a point defined by the previous siege, whenever an invader is damaged by a trap the furthest point that they can see in the direction that they are travelling is recorded, unless they are retreating. So they hopefully generate a path to a point of open ground past the traps.
Or you could mark the last open ground an invader voluntarily moved to before it died, or any any place that an invader triggered a pressure plate or trap as a Low Traffic zone and have invaders avoid them more as more invaders die there.
Or you could just take an average location of all workshops and path to the nearest open ground.
Spies with high resistance to traps and stealth could be used, they would work like snatchers or thieves, maybe pathing to a high-value production task, or an office holder, and a high-skill civilian. If the sight their target, they turn around and try to escape, if they escape then the location of their target is marked as a tunnelling destination.
Various overlays like the depot access view could be used to stop them getting into too much trouble...
Pathing: Include ground in you pathing for tunnellers, this will increase the CPU usage of the pathing so you keep limited numbers of these paths. Mark soil as, maybe, 20 tiles of movement, maybe higher, you need to balance out that tunnelling will probably produce a more direct route. Stone could be 60, maybe adjusted for the type, add a bonus for tunnelling resistant stone, maybe if it is smoothed, maybe if it is engraved, steel walls might be over a thousand, to compensate for the fact that the tiles you want them to dig through are high resistance stones. Make high-resistance materials take longer to dig through, so that if they do decide to path through them that there is still an advantage to high resistance. Generate an overlay of safe areas, this would be tricky for fortresses with above-ground defences. Maybe average out the deaths of active invaders and try to avoid it. You pick a safe spot near the target, generate a path from the target to the safe spot, and start digging...
For some cohesive ideas:
Some units are marked as tunnellers, they use a special pathing script that includes solid ground. If you have a 200 tile-long maze filled with traps and ballista with a single floor-section of soil between it and the surface then the tunnellers will make a shorter route... Some invaders probably protect tunnellers until there are no more tunnellers left. If you have a 100 tile-long shaft going into the side of a mountain, then it is unlikely to be bypassed unless it was very unpleasant. You could add a penalty to pathing for invader deaths. An unfortunate side-effect would be that you would expand the shaft and the invaders would avoid the middle for no obvious reason. Also invaders would path around traps, goblins don't seem the types to memorise a trap because their great uncle was killed by it. You could produce a penalty over a large area to give more of a feel of a bad area than a bad item. Also, particularly old entrances would be completely ignored by invaders. You could have penalties decrease over time, but that would require a timestamp on each event, or you could do it arbitrarily... Maybe they would reset when new siege equipment became available. Also, of nobody survives then at most there should just be a general disease over the most obvious path...
A spy arrives at the fort, it paths to a bedridden dwarf, it doesn't set off any traps and it manages to avoid detection, probably because it doesn't actually path next to anyone and just waits until there is an openning. It marks down the location of one of the beds in your hospital and sneaks off of the map, at which point that enemy has a destination for tunnelling. They send a siege with tunnellers. The siege paths as normal but stops at a safe location and builds fortifications, catapults, and covered food stockpiles. In the middle of the defences the tunnellers designate a path, avoiding open ground as that would probably just lead to a defensive passage. They slowly dig towards your hospital and then pour in and murder all your trainees in their beds. There is probably an init option to see where their tunnel is, but even if it is off, you probably get a warning when they are tunnelling within a couple of tiles of a dwarf...