I dunno - a few thoughts...
Ignorance. Being ignorant - having a lack of knowledge......Lack of knowledge about other races, cultures, nations, about economics, migration, history.....
Anger and dissatisfaction with own life, frustration. looking for someone to blame - look for someone different from yourself, to point and say "it's their fault, not mine".
Seeking reassurance of your 'rightness' by seeing 'wrongness' in another.
Low self esteem..wanting to hurt someone else to make yourself feel powerful. Wanting to feel 'better than' someone or some other group. To feel elevated.
Parental example - growing up with racist parents and accepting that as normal and right.
Out and out thuggary with race being the identifier of choice (iyswim), but not the issue, thug could just as easily hate people under 5ft tall and behave the same way.
There's no one answer. People can be shits for all sorts of reasons.