Why do kids start smoking? Yeah, in part, it is that stupid.
It's human thinking, and I think it is important to not overlap real mental illness with racism.
It's extremely important to not do that.
Mentally ill persons don't choose it. They're not taught it by peers, they're not inducted by recruiters. They often know they're ill and suffer from it and want relief from it. Rather than giving a sense of belonging, it alienates them from friends, family and society, and much too often earns them totally undeserved moral judgments. They get a big dose of discrimination due to "othering" too.
Racists are normal, average human beings who want to feel they belong somewhere. They're not suffering from their racism; actually it succeeds well at solidifying social bonds and giving a stronger sense of identity. Which is exactly the cause of the racism.
So it's a cultural and moral problem. Maybe characterize it as a social illness, but not a mental illness.
We're not born nice and then become aggressively tribal due to an illness. Aggressive tribalism is an evolved trait, and an aberration (a SOCIAL aberration) only because of recent multiculturalism. So it's an issue of morality rather than mental illness. The general point of ethics is to encourage humans to NOT be how they evolved to be. To be ethical is learning to be more magnanimous than what we naturally are when left to our impulsive and social natures
If they were mentally ill, you'd be confronted with a problem far worse than it is. For example, a person suffering life-long depressive episodes simply cannot decide it's wrong and therefore decide to "not be like that" with just some exposure to more "socially healthy" alternatives.
But with racism there's more choice. Observe the vids about KKK members making a big turn-around when social barriers broke down enough that they befriended a black and/or Muslim person. The person just needed to see that "the other" is as human as he is and that it's ok to stop guarding "me and my kin". That's entirely a matter of expanding the circle of ethical regard.