This odd-looking creature is commonly known as the ‘crown wasp’ due to a ring of tubercles on its head but is known by scientists as a stephanid.
Stephanus is greek for crown, thus, Stephanidae.
Its strange body structure can be hard to make sense of, so let me try and explain: The orange/brown part to the left is the head, to the right of that the thorax with the wings attached, and the part sticking up into the air is the abdomen, making up the three major segments of an insect.
But what is that long needle-like structure on the right?
That is the ovipositor, the technical term for an insect’s egg-laying device.
The wasp uses this ovipositor to stab beetle larvae and lay eggs in them, which it does by using its legs to sense vibrations from beetle larvae living inside the rotten wood it has landed upon. After a few days, the deposited egg hatches and a wasp larva develops inside the beetle larva, eventually killing it and emerging as an adult, which then flies off to stab a beetle larva elsewhere in the rainforest and start the process all over again...
Some parasitoid wasps actually use a form of echolocation (just like a bat would) to locate their prey. They have modified antennae that tap the rotten wood and specialized ears on their legs that can hear the tap’s echo off of a larva and locate it that way.
This particular rotting tree had several of these wasps on it, so clearly there were some stab-worthy beetle larvae within.
Note: this wasp is a parasitoid because it kills the beetle larva host, opposed to a parasite which just feeds on it but lets it live.
Read more about these wasps here.