Punishment has been held up as one of these evolutionary puzzles. It's a bit like co operation, people have called it actually a second order social dilemma. One school of thought says that the way that this can evolve is if we have group level competition. The groups with punishers tend to have tend to be more cooperative.
Cooperation is the means by which life arose in the first place. It’s how we progressed through scale and complexity, from free-floating strands of genetic material, to nation states. But given what we know about the mechanisms of evolution, cooperation is also something of a puzzle. How does cooperation begin? A biologist by training, Nichola Raihani looks at where and how collaborative behavior emerges throughout the animal kingdom, and what problems it solves. She reveals that the species that exhibit cooperative behavior — teaching, helping, grooming, and self-sacrifice — most similar to our own tend not to be other apes; they are birds, insects, and fish, occupying far more distant branches of the evolutionary tree. By understanding the problems they face, and how they cooperate to solve them, we can glimpse how human cooperation first evolved. And we can also understand what it is about the way we cooperate that has made humans so distinctive and so successful.