This is a experience I know about all too well.
When I was around 17 years old, I went through a period of hatred. I would frequently insult people online with racial slurs, among other things, despite growing up with a very anti-racist upbringing. My thoughts at the time were "I'm not racist - I hate everyone." In retrospect, it was because I hated myself. I didn't feel I had value, so I didn't value others. I felt powerless, so I attempted to exude power through vitriol.
There were many factors that played into that time in my life. Growing up, I was constantly reminded of how much I was a money-sponge, a dead weight, one more problem to contend with day to day, paycheck to paycheck. I was taught not to take anything I had for granted, which by itself is not a bad thing to instill in a child. But my upbringing went a step further: I was made to feel that I would never be able take care of myself. I was kept from getting a job, getting a drivers license, going to college, getting my GED. If I moved out, I would be a drug addict, I would live in filth, I would starve. I could be anything I wanted to be - but only with my parents support, on their terms.
That frame of mind eventually gave way to my current psychological afflictions (ASPD and NPD), and my phase of hatred was when those disorders began to take shape. Although that period of my life left its mark, I of course recovered from that ignorance and prejudice that ate away at me on the inside. For me, the most cathartic change I made was of my perception of value. In the universe - a chaotic maelstrom of destruction and creation - I can find no inherent value in anything. Nothing we do makes a difference to the grand scheme of things. You must provide your own value, instead of relying on others to ascribe it to you. I felt the racism, sexism, homophobia, xenophobia, and all other lugubrious concepts melt away as I found value in myself, and thus had no need to devalue others to feel valuable.
There are many reasons people turn to this sort of aggression. Some for the same reasons I did, some because they actually feel they are a superior mammal to others, and some for reasons totally unclear to even themselves. Regardless of why, I pity those who have it, because I know first hand how pitiful that existence is.
[edited for typos]