First of all, we must understand that the scenario above is only half true. Why is the scenario wrong? Because we also see "good" people being rewarded for the honest life they live and "bad" people getting what they rightly deserve. Even if a bad person gets away many times for his evil ways, time and again, we find their "luck" eventually running out and leave them paying for their injustices.
And why is the scenario mentioned also partly right? Because the Bible clearly tells us is Matthew 5:45 that God, "maketh his sun to rise on the evil and on the good, and sendeth rain on the just and on the unjust." The Bible is saying that God does allow even bad people to experience His goodness and His own people to experience the difficulties of this world.
So instead of asking "Why does God allow good things to happen to bad people and bad things to good people?", asking "Why can't God just give good things to everyone?", in my opinion, is a better question to ask.
To answer the second question (Why can't God just give good things to everyone?), we must go back to the very beginning of time, to the time when God created everything in six days some 6,000 years ago (Yes, I'm a young earth creationist). If you go back to Genesis chapter 1, we find that God intended to give just good things to man for everything that He has made was "very good" (Genesis1:31). He had no plans of giving man diseases, hardships, natural calamities and even death. What He wanted was that man enjoy the beautiful world He had created. But man sinned against Him when Adam and Eve disobeyed a very simple command. Because of that, the world was cursed. What were absent in the world He made (diseases, hardships, natural calamities, death, etc.) now abounds. Sin has also become a way of life for man. The Bible says that everyone are sinners (Romans 3:23), so technically, all of us are "bad" people and no one from among us can declare himself as "good". We, again and again, offend His Laws, bringing more curse to this world. So in truth, we are the ones responsible for what we experience in this life. God had no choice. We, in exercise of our God-given free will, everyday decide to pollute this world with sin, and because of that, we experience the consequence. Not only that, we also sentence ourselves to an eternity of punishment in Hell for that is the payment for sin (Romans 6:23).
Someone asked, "I'm not as bad as other people like criminals, so why can't God be 'fair' and just give His punishment to those who are really 'bad' people?" Well, I advice you not to demand that God be "fair" because if He does become one, we should all get right now what we rightly deserve, and that is Hell, for again, we are all criminals in His sight as we have all offended His Laws.
With the point in the previous paragraph in mind, we can now answer the first part of our original question, "Why do good things happen to bad people?" First of all, we must see that there is a reason for us to be thankful that despite our sins against God, He has not yet fully given what we deserve (Hell). And the Bible is very clear as to why. Lamentations 3:22 says that "It is of the Lord's mercies that we are not consumed, because his compassions fail not." God is applying His mercies on unrepentant people, that's why they are still in this life. And not only that. He also allows them to experience some of His goodness. And why does He do this? Romans 2:4 tells us that God's goodness leads man to turn away from his sins. That's the grace of God. He gives sinners the chance to get right with Him because He has no pleasure in the death of the wicked (Ezekiel 33:11) but His will is that all should come to repentance (2 Peter 3:9).
And why do "good" people experience "bad" things in life? Again, no one is "good" if God will be the judge as we all are sinners in His sight. But He also has made a way for us to be good and that is by the transfer of Jesus' goodness to us which leads to us becoming His children. I will explain towards the end of this article how one can be "good" in God's sight and how we can become His children.
The bad things happening in the life of a child of God is not because God is punishing them or something. Yes, there are times that God allows sufferings to come to His child because of a misstep he takes. But this is not to punish him but instead, to bring discipline to him, and the reason to this is because God loves him (Hebrews 12:6). Sometimes He allows sufferings as trials that will eventually make His child a stronger person as well as bring him to a closer communion with Him. But for sufferings that come to a Christian that are not because of discipline or as trials, he experiences them simply because he is still in this sin-cursed world. This is not his world as a child of God. Heaven is the place intended for him. But while he is still here, this world will be against him. The Christian knows and understands this fully that's why he accepts, with God's grace, whatever hardships from this world that God allows to come to his life. He also knows that the sufferings of this world is just temporary and will be so insignificant when God finally calls him to Heaven to experience the magnificence of the place someday (Romans 8:18).
God offers to everyone what He has already in-store for His child. What God wants to give a sinner is not a fair deal as again, if we want God to be fair, then it's Hell for us now. God wants to give sinners His grace. His favor that we do not deserve that we can receive through Christ and His sacrifice at the cross. We only need to come to Him in humble repentance and faith in the finish work of Christ, and after that, you right away receive His promised salvation and eternal life in Heaven.
This is the main difference between the atheistic worldview and the Christian worldview when it comes to answering the main question of this article. Atheists, in answering the question, will just tell you that there really is no God if we observe that such a scenario does exist. They offer no real explanation. The Christian worldview, on the other hand, not only explains why this scenario is happening, but at the same time, offers hope to someday experience everything that's good in Heaven.