This is the age old question. Right?: Why do bad things happen to good people? Since we aren't God and don't know 100% His thoughts and purposes, it will continue to be a mystery to us. Maybe we'll understand when we get to heaven. One of God's attributes is His Incomprehensibility. I saved this quote from the book The Extraordinary Life by C. Stanley: "While we have no right to fully know God's reasons, our lack of such information is the very thing that creates our feelings of frustration, anxiety, and doubt. Consider the irony of the situation. If we, in our limited human wisdom, could comprehend God's motives and actions, that in itself would be cause to doubt Him, since His thinking would be no better than our own!
I think part of our problem as humans is that we want to label everything: that's good or that's bad. Maybe in God's eyes there are no such labels. Back to my original statement about bad things and good people. The Bible tells us there is none who does good, that we have all turned aside and become corrupt.
And we really don't know God's purposes. I read the book "A Grace Disguised" by Jerry Sittser recently. It is his story about 3 of his family members being killed in the same car accident. You should read it. He is very open and honest as he walks us through his grief, but especially all the things he's learned through it.