This is one of the classic questions of philosophy, religion, and life in general. Brilliant minds have been working on this problem for centuries, so I don't propose that I will have suddenly answered the question for you here, but I do have an answer that I think can help you move forward.
What I am talking about is assigning meaning.
Here is the deal: none of life's events mean anything at all until we assign that meaning to them. Even the words in the question themselves give us a clue. We have decided what "bad things" are, and we have decided who are "good people."
Let me give a more detailed example.
Let's pretend you and I are walking in a field one night. We both see the exact same lights off in the distance.
You happen to believe in UFOs and aliens. Your mind starts racing about the little green men we just witnessed in a flying saucer above this field.
I on the other hand, do not believe in any of that. I believe we have just witnessed some random reflections, or possibly a plane flying strangely. I also start to wonder what the heck little green men would be doing flying over a field in the middle of nowhere late at night.
We have both witnessed the exact same events, but our beliefs caused us to assign different meaning to those events.
This very simplistic and somewhat ridiculous example shows how different religions and cultures can interpret the exact same events in such radically different ways.
Your beliefs are causing you to assign meaning to events that are happening. If you hold a set of empowering beliefs, you will probably assign empowering meaning to the events of your life.
A Little Southern Girl
I want to tell you the story of an African American girl born into poverty in rural Mississippi, United States.
She was born to unwed teenage parents, and shortly after conception, her father took off, never to be seen again. She was sent to live with her grandmother for a time. Her grandmother was so poor she often had to wear dresses made of old potato sacks.
At age six, she moved with her mother to inner city Milwaukee, where her mother worked long hours as a maid. Again she had almost nothing.
At the age of nine, the sexual abuse began. She was molested by a cousin, and uncle, and a family friend on numerous occasions.
At 13, she couldn't take it anymore and ran away from home. She became pregnant at age 14, but the baby died during birth.
I think we can all agree this is not a good start to someone's life. So why did all of this happen to this innocent little girl? I don't really know, you would have to ask her. Her name is Oprah Winfrey.
You Get To Decide
While I have never spoken to her, I am pretty sure that Oprah would be able to tell you why she feels all of those things happened to her at such a young age. She has developed a set of beliefs that have empowered her, and taken her to the heights of success.
She is the wealthiest woman in the world, and probably the most influential woman in the world. She has done amazing things on a personal and professional level, but has also given back to the world at large.
Your beliefs will determine the meaning you assign to any event in life. No event is either "good" or "bad" until you decide which it is.
So, let's return to the original question. Why do bad things happen to good people? Again, you will have to ask them. You will find it is their beliefs that determine how they assign meaning to those events. You may find they don't believe those events to be "bad" at all.
It is vital to take any self defeating beliefs you hold and turn them around. This is the only way to move from an attitude of victimization to one of empowerment.