Humans are creatures of habit. We like what is familiar.
That goes for other types of people, as well as food, hometowns, etc.
Now being outright, consciously racist is something that probably has to be cultivated and learned, but just being more comfortable with people that look like you is normal.
That even extends to gender.
I like to give this example:
Take elementary school or middle school kids. Put 100 of them, divided equally among boys and girls, and have the go into the gym for the school dance.
Then look at where they are all standing: The boys will be in one group, the girls in another.
You can further divide that up by race. You'll get some crossing over, but by and large, they will naturally separate themselves first by gender, then by race.
Why? Because people gravitate to what they are comfortable with.
Now racism, that comes from taking those natural impulses and ramping them up and aggressively or consciously not only keeping yourself away from whatever race you don't like, but urging others to do the same as well. I don't think that is natural, but given how different people are, it is probably somewhat natural that some people would choose this path.