
Dictionary.com says:
"Word History: The French used pétard, “a loud discharge of intestinal gas,” for a kind of infernal engine for blasting through the gates of a city. “To be hoist by one's own petard,” a now proverbial phrase apparently originating with Shakespeare's Hamlet (around 1604) not long after the word entered English (around 1598), means “to blow oneself up with one's own bomb, be undone by one's own devices.” The French noun pet, “fart,” developed regularly from the Latin noun pditum, from the Indo-European root *pezd-, “fart.”"
seems the modern use of it is probably to gag at the smell of your own farts.