There are many such mysterious mysteries in evolution. Some wasps paralyse a caterpillar of a particular species by stinging it very precisely in its nervous centres, then carries the caterpillar into the nest it previously dug out, lay its egg on the caterpillar then close the hole to never come back.
This is a completely automatic, unintelligent behaviour; if you remove the paralysed caterpillar at any point in the process the wasp simply goes on with its business (it will close its nest without any caterpillar inside, where the larva will die out from lack of food).
In the late 19th century, Jean-Henri Fabre studied these wasps (and many other strange insects) and had a copious correspondence with Charles Darwin on this very matter. His books are absolutely fascinating (ditto the letters Darwin and him exchanged).
> lay its egg on the caterpillar
> it will close its nest without any caterpillar inside, where the larva will die out from lack of food
...wouldn't the larva be with the caterpillar? You said that's where it lays the eggs.
The weirdest insects I've seen in real life are these ones called Burying Beetles - they have chemoreceptors that allow them to detect the odor of a dead mouse from as far away as two miles. Then a male and female fly to it, dig a big hole, strip all the fur off of it to line the hole, then drag it down in there and raise their young together. They are also unusual in that outside of bees and ants, very few insects raise their young together from infancy to adulthood.