If you discover why, you may win a Nobel Prize, but I can offer two explanations. One is that some people enjoy being mean and/or get off on the suffering of others, but this is a pathology, presumably caused by some genetic, chemical, experiential, or environmental factor.
But for most people, meanness and cruelty are a defensive mechanism that springs from vulnerability and fear, real or perceived. For example, many political regimes stay in power by stoking a fear of the “Other”-in this country, most recently, it’s been immigrants, trans people,and Muslims-that often causes meanness to spill over.
In personal interactions, we are most often mean when we are hurt by something someone says or does. Sometimes we’re mean because of group dynamics and fear of losing status.
That’s my current thinking, anyway.