To justify oppression by demonising people, and making people think it's okay to hurt and exploit them.
I did an undergraduate degree in anthropology, and one of the things you first study in anthropology is how anthropology was originally used to justify racism and slavery.
There's a very famous anthropology book where a scientist measured the heads of lots of different people of different races, and wrote a book stating that science (ie head measuring) proved that black people are less intelligent than white people, so white people have to be in charge to protect black people from themselves.
Black bodies were of tremendous financial value as free labour (slave trade), but most people are at least a little bit innately uncomfortable with the idea of kidnapping people (and kidnapping children), repeatedly physically brutalising them, forcing them to do hard manual labour, and killing them if they resist.
But companies and people stood to make huge amounts of money from slaves this obviously was a problem that had to be fixed, so a huge amount of work was done (via propaganda, pamphlets, books, so-called "science", and mainstream media and entertainment such as minstrel shows) to portray black people as violent, angry, animalistic, and stupid. Because if all you ever see or hear is that black people are violent dumb animals, you don't have the same emotional reaction to seeing a black child whipped that you would a white child being whipped.
And then confirmation bias kicks in. If you've been kidnapped, had your kids stolen, been whipped every day, then of course you're going to be angry. Every single slave who lashed out violently was used to further the myth that black people are inherently violent and angry, and therefore need white people controlling them, to keep their naturally violent nature in check.
Generations of black slaves had no access to education, and again this created a situation where their circumstances reinforced stereotypes that black people are less intelligent.
All so people could make money off of black bodies.
(Clearly that is a massive, massive oversimplification. But it's important for people to realise that money and capitalism plays a huge role in how and why people create and push stereotypes, and how many stereotypes came about originally from very deliberate, planned and organised propaganda campaigns.)
It's the exact same thing with Jews. The history of antisemitism is rooted in money. In the Middle Ages, Christians weren't allowed to be money lenders, so that job often fell to Jews, or Jews were actively forced into those jobs. That resulted in a situation where lots of Christians (who were the powerful majority) owed Jews (a powerless minority) money, and obviously they didn't want to pay, so it was in their own financial interest to invent lies and slander about the people they owed money to to justify not paying the debts they owed. Instead of paying their debts they started to call the Jewish people they owed money to money-obsessed and money-hoarding, which are stereotypes that exist to this day.
And then Jewish people all over Europe were expelled from their homes, there were genocides and mass expulsions, and violent oppression. Many Jewish people became refugees. So Jews started keeping their money in gold rather than in banks, so it would be portable and something they could use in any country. (This is true of my own family to this day.) Jewish people who were owed money insisted those debts be paid. And so the stereotype of Jews being money-hoarding was reinforced.
After WWI, Germany was broke and people were starving (due to the harsh penalties forced on Germany in the Treaty of Versailles). How did the German government react to the fact they couldn't afford to feed their own citizens, due to the fact they lost all their money fighting a failed war? Did they take responsibility for their own actions? Did they blame the countries that signed the Treaty of Versailles? No, they blamed it all on Jews living in Germany, and that led directly to WWII and the Holocaust.
And then many Jews all over Europe wound up as refugees, having fled or survived the Holocaust, so there was a huge movement to give Jewish people their own country (which was pushed mainly from European countries wanting to get rid of Jews), which led to the creation of Israel, and that obviously has not exactly ended well.
The exact same thing with women. For centuries men have tried to paint women as hysterical, as weak, because we have what they want (basically, vaginas, and the capacity to have babies). Most of the stereotypes around women were created by men as an excuse to control us.