Haven't done it myself, but I think the construction is basically a lever on top of a support (well, a floor to put the lever on, on top of the support). The lever linked to the support, a drawbridge to get access to the lever without supporting the floor, and a ring of cage traps around the support. Gremlin pull lever. Gremlin falls, Gremlin knocked out by the dust, Gremlin caught in one of the cage traps.
Before the structure is build, the Gremlin is likely to leave unless you block the access, so you'd have to lock it into you fortress and seal it to the caverns while building, I think.
The best way to plan this is actually to herd the Gremlin into a room locked with a drawbridge and keep it locked up there while you build your trap just outside of that room (it also means you don't have to abandon cavern access during the building). Releasing the Gremlin ought to get it to fail to resist to pull that shiny lever.
How to herd the gremlin? Probably using military with station orders (non missile users), but military with scent of an enemy tend to ignore further station orders and pursue their prey (or charge an undead horde to their certain death). An alternative might be miners that you control by designating stone to be mined (cancelling the order before they've mined it).
Edit:
Another way to get a non mandate mayor is to replace the mayor with a non mandate dwarf after each election. Careful check of their preferences should allow you to find a suitable candidate). But a Gremlin mayor is cooler...