That's not being treated differently. If someone is shouting in anger at him for a reason unrelated to race, what is, said is of less consequence than the fact its being shouted. Angry people say a lot of things they might later regret. Often angry people are just trying to push angry buttons in the other to provoke a reaction. Just anything that might hurt.
And why would the person shouting "nigger" at your friend think it might hurt? Because the person shouting it is a racist and thinks the word "nigger" is an insult.
Just change it up. Your friend isn't black, he's asian and Person A calls him a "nigger" in anger as an insult. Is Person A a racist? Yes, because he (a) thinks being a black person--aka, "nigger"-- is an insult and (b) is comparing your asian friend to being a black person by calling him "nigger" in anger.
Once again, "nigger" has no alternative meaning. It is a pejorative term that reduces and denigrates all black people to being subhuman. If I am calling you a "nigger" in anger, I am calling you a subhuman being. Your own skin color may not be full of melanin for it to nevertheless be racist for me to call you a nigger.
So, unless someone is calling your friend that
as a tasteless joke and not in genuine anger, then, again, I don't see how it's not racist. I've said a lot of things in anger, but calling a black person (or anyone) "nigger" in anger would only reveal my perhaps here-to-fore latent racism.