It comes from our genes. We have evolved to seek status. Status gives us an evolutionary advantage. Everyone prefers to mate with high-status individuals, whatever makes them high status. Thus people seek an advantage over others using whatever will give them that advantage—mostly stuff, these days, but also intelligence and creativity and strength all work as sources of status, at least for men. Women get an advantage from beauty, but also intelligence and creativity and other capabilities.
Over time, people seek these advantages, and then they try to keep them. They try to pass them on to their progeny. People build organizations to keep the status advantage.
Ironically, one organization that builds status very well, officially does not use that status for an evolutionary advantage. The Catholic Church forbids its officials from entering into reproductive relationships. Of course, they happen anyway, but officially, it’s a no-no. What this does, however, is it allows the Church to accumulate wealth and status and power and keep it through the centuries. It is never lost due to inheritance issues.
In any case, as long as humans are human, there will be a hierarchy and a class system. People will always compete for an advantage, either in reproduction, or in power or other ways of measuring status.