It’s the perennial Problem of Evil (or, in modern terms, the problem of Cluster B Personality Disorders).
And nobody has ever been able to solve it. Not religion, not moral philosophy, not civic or moral education, not political philosophy, none of it. The sociopaths and narcissists will always infiltrate, corrupt, and eventually corrode, any institution, public or private, wherein they find they can gather power, prestige, and wealth.
Discover a cure for Sociopathy and Narcissism, and you solve 95% of humanity’s problems overnight.
If monotheism cures sociopathy and narcissism (i.e., evil), then the Middle Ages - when the Universal Church ruled Europe and placed religion into every aspect of public life - would have been a Golden Age of peace, brotherhood, and loving kindness.
Alas, it was not. Creepy assholes just moved in and ran the Church and the State. And it all started with Constantine (“hey, Jesus visited me and told me that he’s real, and that I should be running everything by threat of violence. How neat is that?”). And continued on from there - justifying violence and exploitation through divine fiat (“trust me, God says the land and gold all belong to me.”). That’s how it works.