Some additional info:
This phrase originates from the play Hamlet:
There's letters sealed, and my two schoolfellows,
Whom I will trust as I will adders fanged,
They bear the mandate, they must sweep my way
And marshal me to knavery. Let it work,
For 'tis the sport to have the enginer
Hoist with his own petar, an't shall go hard
But I will delve one yard below their mines,
And blow them at the moon.
(Act III, Scene 4)
According to the Oxford English Dictionary, the word petard came into substantive use in 1598, so it's fair to speculate that viewers of Hamlet (first performed c. 1600-01) may have been aware of the word's etymological root in the French pétard, from the verb péter, to fart. This would have given the phrase an additional, probably intentional, double meaning (i.e., being flung into the air by one's own flatulence), alluding to the humor and ridicule associated with being caught in a web of one's own machinations.