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.
Heb. 12:7 It is for discipline that you endure; God deals with you as with sons; for what son is there whom his father does not discipline?
Heb. 12:8 But if you are without discipline, of which all have become partakers, then you are illegitimate children and not sons.
Heb. 12:9 Furthermore, we had earthly fathers to discipline us, and we respected them; shall we not much rather be subject to the Father of spirits, and live?
Heb. 12:10 For they disciplined us for a short time as seemed best to them, but He disciplines us for our good, so that we may share His holiness.
Heb. 12:11 All discipline for the moment seems not to be joyful, but sorrowful; yet to those who have been trained by it, afterwards it yields the peaceful fruit of righteousness.
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: