I think it developed organically, for many different reasons. And, over time, was corrupted for the benefit of those who could use it to take advantage of the people around them. Which, sadly, makes it like so many other human endeavors: business, finance, government, and so on. Created to meet a need, developed as societies grew, and abused by grifters.
The survival instinct keeps doing its thing, even when it is detrimental to the group and, therefore, the individual.