For example, in The Shield, the cop character Shane is super racist and says the N-word, but when a Black girl is killed, Shane gets really mad and wants to find and kill the killer or bring him to justice. Some CEOs who are straight-up classist would still help their employees, and if their employee dies, they would start funds for their kids. But why? Why would people like this do something ‘good,’ especially when there isn’t anything in it for them?


Many comments have alluded to this: people are contextual.
I’ll add to this that thoughts are very, very flexible.
In some contexts we learn to think one way and in other contexts we learn to think in other ways. Our thoughts always get activated by context, either external contexts or internal contexts. For example seeing an apple might have us think we’re hungry if we’re hungry. Or it may make us think we don’t even want to see it if we just ate a lot. Or we might think of our upcoming presentation and that may be the context for the thought “I’m not prepared enough”.
Not only are thoughts contextual, but they behave in interesting ways. Often, we transfer thoughts from one context to another context. If we think “I’m never prepared for presentations”, we might end up reinforcing ideas like “I’m never prepared [in general]”. We may end up thinking we’re never prepared for dinner with friends or for tough conversations with loved ones.
Another critical feature of thoughts is that we can even change the role thoughts have in our behavior. For example, the thought “I’m not prepared enough for my presentation” may be seen as a literal truth. Or it could be seen as a thought and just a thought. In other words, thoughts can sometimes be taken literally and we can be fused with them or we can look at them from a distance.
These three examples illustrate my point: thoughts are ridiculously flexible.
This flexibility is what explains the phenomena you notice. That is how we end up with a capitalist who may have strong thoughts about family and may stop focusing on profit-maximization when their employee’s daughter die. That is how we end up with a worker who could have strong thoughts about profits and may stop focusing on solidarity with his peers when a promotion is offered.
My perspective comes from contextual behavioral science and relational frame theory.
What terrifies me, is I feel like a lot of younger people no longer can separate out words, thoughts, and reality. They seem to think if you ever have a racist thought once in your life you are irredeemable forever… it’s wild.
It feels like a evangelical christian craziness, just focused on race rather than sin.