Something about how one group behaves causes another group to hate them. This induces a bunker mentality in the first group: we must depend on each other for support. Us versus them. Group solidarity. Strong feeling of allegiance to the group.
Curiously then, the behavior which induced hate against them has caused the group doing the behavior to become stronger. Then, groups which can inculcate such behavior into new members, probably the next generation, will survive because of this induced strong group identity. Groups which fail to inculcate the behavior will dissipate, its members perhaps assimilating into another group, the groups no longer needing to be bound by the bunker mentality.
There's an evolutionary aspect to it: the behavior which induced hate could have been discovered by accident, by randomness, but only the most "successful" behaviors survive, perhaps becoming fine-tuned over the generations to induce just the right amount of hate and bunker mentality.
Therefore, the groups that currently exist and have been around for a while are likely very good at inculcating hate-inducing behaviors to each new generation. Can the cycle be broken? Should it be broken?
Religion is of course the famous collection of groups oppressing each other, but many other instances of groups hating each other (for reasons of the other's behavior) exist in society.
There's a reason you despise Them.