I know the easy answer is that people realized that racism is bad, but there's got to be some reason for it happening. In 70 years we went from institutional racism to America having a black president. From colonialism being accepted practice to nations apologizing for colonialism. It seems all so sudden from a historical perspective.
Did people themselves become less racist, or was it more of a generational thing? Was it in reaction to the horrors of imperialism and the Holocaust? If so, why did nations not involved (i.e. Ireland) see a change in beliefs? Has this belief change been observed in non-Western cultures? Why did the change happen so quickly?
I don't want to discourage historical discourse, but this particular trend can be explained by regression to the mean. Here is a reasonably informative Youtube video on the concept.
The basic idea is rather simple: if you select an extreme sample (such as an underperforming student) they will tend to return to the average. This is because your selection criteria was biased: you specifically sought out an underperforming student, so you were more likely to find students that were performing poorly compared to their personal average ability. After a longer study you see that they do better on average than your first test suggested.
Western racism - especially american racism - became common as a result of the american slavery system (here is a more in-depth discussion). White slave owners found it a convenient justification for their actions. Even after slavery was abolished, racism persisted as a means of enforcing class distinctions (even today black skin is associated with poverty and thuggery in the USA).
However, the height of american racism can be seen as an outlying event. While it was not the first time a nation has instituted widespread enslavement, that level of forced labor is not common throughout history. A cynical student of history would probably predict that such slavery would end eventually, and when slavery ends the need for widespread racism also subsides.
You could also view the global shift away from racism and towards tolerance in terms of the civil rights movement. A lot of that stuff goes back to Greek philosophers who first wrote down ideas about equality individual freedoms. These ideas were revived in the Renaissance and eventually morphed into the ideas of civil liberties that are often discussed today. However, I am not too familiar with the history of the movement myself, so I will just leave it at that.
America has a Black president in part because of changing demographics... there are more non-White people in the US than ever before.