A major factor in determining individual behavior is social norms, internalized rules about the appropriate way to act in a certain situation. Humans constantly monitor other people and their environment in order to determine what the correct norms for the given situation are. They also monitor others to make sure that the others act in an acceptable way. In other words, people do as others do and the group makes sure that the rules are followed. But when there are no people around, as is often the case in an anonymous urban environment, the monitoring of or by others does not work. In such an environment, criminals are much more likely to get away with robberies, thefts and vandalism. When there are no or few people around, individuals are forced to look for other clues—called signals—as to what the social norms allow them to do and how great the risk of getting caught is. An ordered and clean environment sends the signal that this is a place which is monitored, people here conform to the common norms of non-criminal behavior. A disordered environment witch is littered, vandalized and not maintained sends the opposite signal: this is a place where people do as they please and where they get away with that, without being detected. As people tend to act the way they think others act, they are more likely to act "disorderly" in the disordered environment.
People engage in racist behavior because it's thrilling or upsetting to others, but above all because they can. By challenging or criticizing them in public, we're putting the brakes on their actions. We're showing them there's a penalty for violating society's norms.
Critics might say that changing someone's behavior doesn't change the underlying thoughts. A couple of comments on that. One, the Skinnerian school of psychology argues that changing behavior does change the underlying thoughts. Two, changing the underlying thoughts is a secondary goal. Stereotypical words and images are harming minorities now. The proper response is to end the harm now and worry about the causes later.
For more on the subject, see For more on the subject, see The Harm of Native Stereotyping: Facts and Evidence and Why Write About Native Americans.
Below: A "harmless" broken window in the field of race relations.