The title question has always puzzled me and I am sure to thousands or millions of people before me. Why bad things happen to good people and good things happen to bad people. If good and ethical behavior is no insurance against misfortune and pain, then what point is it?
Religions explain this unexplained balance is by introducing the concept of afterlife and almighty.
We cannot explain what we see, so we conclude there must be something we can explain but cannot see, with the assumption that balance must be preserved. If we cannot explain things in terms of actions of humans and animals around us, then there must be something or someone beyond seen life i.e. God. If we cannot explain the contents of life of humans and animals, then there must be life beyond death, i.e. afterlife.
A while back I posted the Story of Tao. About how your perception is a “catch-up” between your expectations and state of the world. And your expectations can change and the same state of the world is interpreted totally differently by you.
On one of my walks, I stumbled upon an hypothesis. Ethical behavior is not so much about avoiding bad experiences and pain. They simply cannot be avoided. Good and bad is part of life. It will always be there.
But with ethical behavior you will find yourself in cognitive resonance with the universe. You will gain insights and wisdom. That will eventually lead to enlightenment.
If you were to keep an account of material gains, it will be pretty much the same for ethical and unethical behavior in the long run.