I needed to unpack some experiences after doing data privacy work in public health units and a health ministry, so in trying to understand what I saw, I read:
Eichmann in Jerusalem: A Report on the Banality of Evil, by Hannah Arendt, with a critical forward by Amos Elon.
I found her observations about the moral conditions behind people committing atrocities were made on behalf of humanity in general, but somewhat at the expense of a necessary respect for the (then) new nation Israel at the time. I understand the criticisms of her, but I think most of her conceits are worth forgiving to understand how important her observations were.
She did derive a formula by which these things occur, since as a philosopher, she was able to see the role of ideologies as objects and moral mechanisms, with the trial evidence and dozens of hours of his testimony and psychological interviews as the example. Much of what she describes resembles normal government bureaucracy abstractions and what we recognize as crowd behaviors today - but driven by the zeal of a nihilistic inevitability, a sense of privileged enlightenment ("a bearer of secrets"), and a base materialist ontology. His defense was that he was dutiful, everything was "legal," it was an "act of state," his victims actively cooperated, the killing was "a medical matter," and that this was a sufficient moral basis for orchestrating a genocide.
I've found that the evil is far upstream of action, it begins in the blunting and dulling of the human spirit with cliches and ideology, and the horrors are a downstream effect of what was set in motion much earlier. I've read her "origins" book as well, but I'd recommend this one as more directly illuminating.