Praying mantises sometimes eat their partner because it provides extra nutrition, especially for the female. The added protein and energy can help her produce more and healthier eggs.
It doesn’t happen every time—mainly when food is scarce or the female is stressed. In some cases, the male still manages to mate even after being partially eaten, because mating is controlled by nerve centers in the abdomen.