” Hoist with one’s own petard” – to fall victim to one’s scheming.
As with so many phrases its origins lie with Shakespeare, and specifically the play Hamlet, wherein Hamlet tells his mother, Gertrude, how he hopes to outwit Rosencrantz and Guildenstern who have been ordered to take him England and have him killed.
For ’tis the sport to have the enginer Hoist with his own petard; and ’t shall go hard
So, the word engineer, etymologically related to ingenious was in Shakespearean times not a maker or controller of machines, but a bomb-maker, a petard being a small bomb. To be hoist would imply being thrown skyward by the explosion of the bomb one had made.
However, things are a little more subtle, as often they are with Shakespeare. The word petard also means a firework or firecracker and there is an implication of not only a flash and an explosion in the use of this word but a release of something malodorous. This brings us to yet another double entendre. Shakespeare spells petard as petar in some folios and this may well be deliberate is relates to a French term for flatus, pet, in other words, a fart; the French for breaking wind is pétarade.
So, being hoist by one’s own petard could, in Shakespearean lingo, imply that someone has released noxious gas and been caught out. In a more detailed article on this topic (here), the conclusion is that “hoist by one’s petard” is actually synonymous flippantly with “he who smelled it, dealt it”.