"Ultimate attribution error is the tendency to internally attribute negative outgroup and positive ingroup behaviour and to externally attribute positive outgroup and negative ingroup behaviour. So in other words, ultimate attribution error arises as a way to explain an outgroup's negative behaviour as flaws in their personality, and to explain an outgroup's positive behaviour as a result of chance or circumstance."
https://en.wikipedia.org/wiki/Ultimate_attribution_error