In reflecting on times when the Bible did identify punishment as coming from God, in each case, the people were previously warned. Just a few examples: The apostle Peter referred to Noah as a “preacher of righteousness.” Just before Sodom & Gomorrah was destroyed, Abraham was concerned about good people being indiscriminately destroyed with bad ones just because of living in the locality. (As a result of that, Lot and his family were safely escorted out of that area before God's judgement was carried out.) Before disobedient Israelites were taken into exile in Babylon, God made sure to give them more than adequate and repeated warning. Finally, most know the story of Jonah and the whale. The reason Jonah ended up there was because he was told by God to give a warning message to a city. Instead, he ran the other way. After being vomited out, he decided to carry out the commission to warn the inhabitants of Nineveh. The positive results are recounted here.
So what four points should we keep in mind when bad things happen? First, God is not the cause of "natural" and man-caused disasters that indiscriminately destroy both good and bad people. Second, unforeseen occurrences befall all people. Third, in cases where God does punish disobedient humans, they are warned first. Finally, God is able to selectively save those faithful to him in cases where he does punish people.