Create a hallway full of bridges that open outward. Tunnel a 2 or 3 wide chamber on either side of this hallway. When the bridges are up, those two chambers are locked in tight. When the bridges are down, the entire hallway floor is covered by the bridges.
Put two more bridges, at the two ways into the hall, and alternate them so that when the hallway-bridges are up, the bridges at the entrances are down, and vice versa. The entrance bridges seal in the hallway when the trap has been sprung. Put an antechamber right after the first bridge, the one sealing the entrance from the wild, where the goblins would come from, so that when you pull the lever and have all the bridges alternate, they aren't smashed into pulp by the bridges in the hallway. That'd defeat the purpose! Put a bridge that raises in the direction of the hallway covering the antechamber on a separate lever, for clean-up after.
Put the necromancers on either side of this hallway. Fill it with corpses for them to raise, so that the chambers are filled with undead.
When goblins come, let them get into the antechamber and then pull the lever. Goblins are sealed in, the undead are released, and a massacre ensues.
Any surviving undead or goblins in the antechamber are then flung back into the hallway by the antechamber bridge, this is why you want it raising into the hallway and on a separate lever.
Then you pull the main lever, which should fling every undead and goblin back into the necromancers chambers to be saved for the next goblin invasion. Any loss of undead should be fixed by the influx of new goblin corpses!
I've never gotten a necromancer so I don't know if this would entirely work, but try it~ On a back-up save. With lots of testing before you add in necromancers or try it on goblins. >_>