This is called an osmeterium! It’s a defensive organ found in all swallowtails caterpillars. They evert it when disturbed, as you saw above, to either startle their foe or gross them out with the foul-smelling secretions the organ emits :)
What you call given em the ol' stink eye.









