Bad things don't happen to good people because what seems like bad things actually happen for the good and what seems like good things actually happen for the bad, and so it keeps repeating. Whatever is bad will become good and whatever is good will become bad to become good to bad and so forth and on and on it goes.
That is how the good and the bad duality/energies play out and they always aim to reach a balance. Once a balance is reached, it makes a person grow. Then again another growth cycle of good and bad repeats and that is how we as individuals keep growing. In this context, there is no good and bad. Eventually you come to realize that judging what is perceived to be good and bad does not serve any purpose other than resisting the flow of life. Acceptance on the other hand, makes you stop judging and no longer resist the flow. Everything that happens, simply 'is', it is the mind that labels it to be 'good' or 'bad' and then create resistance to life situations. Every situation whether you label it as 'good' or 'bad' is only there to make one evolve and grow. So it is important to start flowing with the river of life rather than resist it and only then can one enjoy the ride, even the turbulent parts.
Here is a very simple example to kind of put things into perspective. Lets say you are unemployed and your bank account is running dry. Its a tough and difficult situation. A job is what you desperately need. Its a terrible situation to find yourself in. Finally, after months of applying and trying, you get a job. Now, getting this job is the best thing that could have happened to you considering the circumstances. You are ecstatic, relieved and finally things fall back into place.
So you begin your new job with much enthusiasm, in the first few months you love it. You finally have the financial freedom and it feels so good. Now as the months go by, say a year or two, the new job which bought you so much happiness is now making you miserable. It could be because of the horrible boss or your job becomes boring or you have too much work with too little pay or there is no growth at all or your colleagues are giving you a hard time etc. So now suddenly, what was once the best thing in your life has become your worst nightmare. The good turned to bad.
So because of your current situation, you start looking for a new job. And soon enough, you do get a new job. And this new job has better pay, more responsibilities, is a better company and you are a lot more equipped to face the challenges due to the lessons learnt in your previous job. It has made you grow. So the bad now again becomes the good. Sometimes it may be a while before the new job comes along but eventually it will, you are pushed to get it.
And this is how we navigate life and when we resist, judge and label situations, we create misery and suffering for ourselves. So even if getting the new job takes a long time and you feel stuck, the key is to stop resisting it and have trust in the Universe that the 'bad' you are currently experiencing will eventually turn 'good'. That is the design!
Therefore, a more accurate way to put it is, "Bad things don't happen to good people, what is perceived to be bad things actually serves a greater good although it may seem bad or even terrible at first."
Now, if you have lost a loved one, it is very difficult to understand or even accept that such a terrible event can serve a greater good. But it does! You may not know it, you may be completely unaware of it but experiencing the loss of a loved one serves the growth of your soul in ways which you cannot understand or comprehend.