This is one of the toughest questions of all. I think all believers anticipate God explaining that in the end. Job asked that question and was answered by God who basically told him that he didn't have the ability to understand and that his question was quite insulting and presumptuous. Maybe that sounds a little harsh, but if it's the truth, it's the truth. Sometimes the truth hurts.
The Bible tells us that certain infirmities happened to reveal the glory of God. It also tells us to endure all hardship as a form of divine discipline that demonstrates God's love rather than his brutality. The Scripture also tells us that hardship makes us better and that Jesus himself even prepared himself for his ultimate death by the things he suffered. Perhaps the title of Sheldon VanAuken's book, A Severe Mercy, best captures the idea of pain and suffering actually serving a good purpose'as being a kind of mercy in reality.
The Bible says this world is a battle ground in which sin and suffering will finally be banished forever. No one goes to a war zone expecting a rose garden. It's a fight and therefore there will be pain and suffering and death. It's the same with the spiritual battle here. There is pain and suffering and death. But, God has made it clear that if we live and serve in Christ that we are actually even more than conquerors because the victory has already been assured in advance. God promises to work out even our suffering for good. He promises that he will work it all out in conformity to his will.
You see, pain and suffering are not from God. They are actually a product and byproduct evil. So much of the human suffering today is caused simply by the evil of others, including what we inflict on ourselves. And, if you look just a little deeper it might become clear to you too that there is an evil force out there who seems to universally be inspiring certain people to perpetrate the most outrageous of atrocities.
Bad things happen to good people because they're living in a world gone bad. And still, a lot more good than bad happens anyway. Just take the time to count your blessings and see if they don't far outnumber the problems and greatly outweigh the pain over the long-haul.