It's an inherent problem of the human condition, for some reason our own moral compass becomes dysfunctional once the authority and therefore responsibility is with someone else. It's the reason the Stanford Prison Experiment went so wrong once the professor took influence; we're not inherently evil, we (as a species) are just drawn to the current ruleset as dictated by our social group or idol of choice, especially if we get convinced it's somehow necessary.
Obviously not trying to abolish any guilt here, people are still responsible for what they're doing.
In the end we need way higher quality of education globally, better social security, rethink society (don't have children be on their own and make parents constantly burned out, god damn it) as well as political systems so they are designed to prevent any definition of an in- and out-group. Protections for who, what, where and how people are are great, and stuff like Germany's Article 1 is a good start, but it needs to go way further.
We need to design an environment that allows us humans to become more than we currently are if we ever want to get out of this cycle.