Why do our brains act in such a evil way sometimes that hurts other people? I have seen some real evil acts. And I almost lost confidence in humanity.

Why do we become so evil sometimes that hurts other people?

I guess everybody knows the Renaissance novel Les Miserables by Victor Hugo. There in the story, it is depicted how a person from the lowest echelon of the society stole a loaf of bread because his sister's child was hungry and how he was punished for years in hard labor during the industrial revolution.

So evil or injustice reveals itself such sometimes that we are compelled to question why? Why do we have to be so evil when we have this beautiful world just in front of us? Is it because of how our brain chemicals perceive things sometimes?

If a person is envious or jealous or has unjust anger and an MRI could be done right at that instance, would it show why we are evil?
MVR there are many hormones within us that motivate behaviours that served a purpose in previous (phylogenetic) environments that in our modern society may appear to be evil.

Oxytocin for example (the so called love hormone) spikes before conflict, and one of the biggest dopamine hits we can ever experience is by punishing someone.

Sapolsky 2017 - Behave: The Biology of Humans at Our Best and Worst