There are plenty of examples of people following orders to commit what are widely considered immoral acts. Some argue that people do so because they follow the crowd, are afraid to defy authority, or believe they are not responsible (lost agency). However, I wonder if in many cases people identify with the authority figures (and the group the authority figure presides over) and adopt their beliefs.
Jim Emerson discuss this in his article on good and evil in superhero movies:
It’s so easy to claim that Evil People just decide to Do Evil because they are Evil (totally unlike the rest of us!). But the truth is, many Nazi war criminals and those ordinary people who actively or passively collaborated with them weren’t all, as the cliché has it, “just following orders.” They believed the horrors of genocide served what they saw as a greater purpose: maintaining the purity of their beloved Germany, their race and their empire. So, as difficult and terrible as it might be…, the Final Solution was, they believed, a noble calling in the long run. …They weren’t monsters — they were people like you and me who found themselves capable of doing monstrous things in the name of a Great Cause in which their faith was pure and fervent and unshakeable.
Emerson also pointed to Alex Haslam’s appearance on Radiolab, in which he argued that participants in the Milgram experiment identified with the group (and authority figure) that were carrying out the experiment:
They’re engaged with the task. They’re trying to be good participants. They’re trying to do the right thing. They’re not doing something because they have to; they’re doing it because they think they ought to.