Many preachers I've heard say God doesn't punish us, but He does allow bad things to happen to us. But I can see examples in both the Old and New Testament where people were punished for their actions. How are we to respond to these?
Every trial is from God and we should thank Him for all of them. Some trials are spiritual attacks of the enemy, but all trials are determined by the Lord. But these trials are not necessarily punishments, since the Lord tests our faith in many ways to train us and produce spiritual maturity. Because He loves us, He brings us trials the Bible says.
Sometimes our trials will come as a result of our mistakes or the mistakes of others, but other times the Lord brings trials upon us even though we have not sinned. The book of Job is the best example of this possibility. The Lord brought great trials against Job not as punishment but in order to show Job was righteous. Job did nothing wrong, yet the Lord allowed Satan to take the lives of Job's family, destroy his business and harm Job physically.
Knowing that the enemy is at work around us is certainly helpful to understanding how to respond properly to trials, but there is no meaningful distinction between a trial involving an attack of the enemy and some other trial (like a natural disaster). Every trial is from the Lord as He says in His word: