Ahh, yes. Racism in fantasy. cracks fingers I'm going to be outing myself as a complete psycho today, and I'm going to love every second of it.
Sorry fellas, this might end up being a little bit of a rant. Tread carefully.
'Racism' (and I admit, I'll be casting an awfully broad net on the term as I use it here) is actually a really nice way of adding little shadings of depth to your worldbuilding and story. A relatively "soft" example of this is the animosity between elves and dwarves common in high fantasy works; aside from leading to cool banter (such as a certain, immortalized moment in LOTR I won't mention here) it helps to show two even-handed truths about racism:
1. 'racism' comes in a wide variety of shades and degrees, and isn't always of the incredibly dramatized and hammed-up variety you see most writers portraying it as.
2. Every race is guilty of racism, unlike the typical (and quite boring) oppressor/oppressed dichotomy that most works end up going for.
On a slightly more serious level, racism is also a decent way to bring realism and depth to your world, if done relatively even-handedly. It can even be a good way to contextualize plot events, such as growing tensions between nations or something along the lines of "there's a series of crimes being committed by people of a certain demographic, so people start distrusting a major character of the same demographic a lot more".
Now to the really fun part: When is racism in fantasy stories bad?
Almost every time it's ever been made a big deal of.
"Fuck thinly veiled allegories, fuck watching your every step to make sure you don't piss off SOMEONE, SOMEWHERE on the internet, and fuck one-sided, context-avoidant portrayals of racism!"
Those are words you can repeat to yourself whenever you're unsure of what to do when you want to implement racism into your story.
Thinly veiled allegories. AKA "I refuse to use any critical thinking on the concept of racism and how it fits into my world."
The truth is, I normally detest allegories, particularly poorly done or poorly concealed ones, simply because they tend to suck as stories. Admit it, you're not George Orwell, and you probably never will be if you have to look for advice in this thread. What most people who think writing this way is a good idea fail to notice (or don't care, in more experienced cases) is that trying to push a message will nearly always come at the expense of the story, even—perhaps especially—if you plan around it. So, if you think writing about racism in this way just to "make a statement" about modern culture is a good idea, I implore you to ask yourself this question, honestly: Do you want to write a good story, or do you want to write a piece of propaganda? Because the odds are very good that you aren't even close to good enough to have it both ways.
And I won't even go into how overdone such a parable would be in this day and age.
just writing your racism as a near-carbon copy of racism in America in a medieval fantasy is ironically a very good way to make your work far, far less realistic than never having racism to begin with, and the main reason for this, in my mind, is obvious in hindsight but very easy to miss. It tends to be very, very one-sided because it is looking at racism from a very specific lens, not a wider anthropological or psychological perspective.
How to avoid this? Ditch the oppressor-oppressed dichotomy immediately. In other words, ironically, in order to have better racism you need more racism. Don't just make the white-equivalent race mega racist when the POC-equivalent race(As far as they are portrayed in the story) is somehow not racist at all, even though every encounter a major character of that race has had with white-equivalents has been extremely negative. Hell, why are they even cognizant of the concept of racism instead of just assuming that "they're all like that"? THAT'S FREE CHARACTER GROWTH YOU'RE LEAVING ON THE TABLE!