That is an ovipositor, not a stinger. These wasps use that long ovipositor to drill holes through the bark of trees in order to lay their eggs. One of my goals next summer is to see the drilling live and close-up. They keep the ovipositor at a 90° angle to their body while they are drilling. This Ichneumon wasp was in the house in the window. After photographs, we took the screen down and let it out into the wilderness to lay those eggs. I wish I had followed it.