Everything is a misunderstanding. It's simply a matter of insufficient understanding, and what appears to be "evil" disappears in an instant. There is no absolute "evil," but simply a difference in understanding.
There are many times when we think we understand, but we don't.
It is common for people to believe they are aware of their true self beyond the ego, but in reality, they only see the ego. And the more firmly these beliefs and understandings are held, the more likely they are to manifest as "evil."
As often said in spiritual teachings, there is a distinction between the ego and the true self. The ego, in yoga, is called "ahankara." It arises as a reaction when the mind (manas), which stores memories, fluctuates as the "chitta" (heart), and becomes rational as the "buddhi" (intellect). When the ego (ahankara) mistakenly identifies itself as the true self, and when certain conditions are added, it becomes evil.
The ego itself is not inherently evil, but when conditions such as environment and experience are added, the ego becomes stronger, prioritizing itself above all else, and as a result, evil arises.
Even if one studies spirituality, there is a possibility of falling into evil if one has not yet discovered their true self.
While morality, discipline, or habits can prevent evil from manifesting, there are also cases where the ego arises due to environment and experience, leading to evil.
To prevent this, the first thing is the environment. Evil cannot grow without the nourishment of evil.
Next, the most important thing is to discover one's true self. In yoga, the true self is called "Atman," and in spiritual terms, it is called the "Higher Self." When one realizes that their true self is a part of the great "world" or "universe," there is no longer a need to fall into evil. This is because, when one discovers the true self, Atman, or the Higher Self, the ego disappears into it.
The ego is a very small thing.
However, even though it is small, the Atman or Higher Self is so vast that the ego dissolves into it.
Therefore, in reality, the ego is even expanding. However, even this expanding ego is absorbed into the even more expansive Atman or Higher Self, so it is impossible for the ego to become evil on its own.