Why do bad things happen to good people?1.) Free will.
2.) Dynamic environment.
The other point is God has promised all things work to the good for those that love Him. We may not see the good He brings out of our troubles this side of eternity but we can take Him at His word... He will bring us good out of even the worst most hopeless appearing situation.