You may be confusing acts of judgment by immoral ones. It is the creator's prerogative to destroy his creation if he so pleases, any time for any reason.
That God doesn't do so, but follows himself rigid reasons is a different thing. In the OT, we have the dealings of God vis-a-vis God's people and vis-a-vis the ones who showed themselves enemies of this people sometimes for no reason whatsoever.
When people who do not believe in God read these accounts they find fault. What they forget is that when a person is killed -- this is pretty final for that individual and for humans. To God this is just a pausing of the video button so to say -- if that is what he wants it to be! God therefore used the actions of the Israelites and their enemies to demonstrate to us his power, and his dealings with people who dare to fight God through his people. These are destroyed -- that is the lesson we should learn.
The ones who were destroyed in the past shall receive on judgment day their chance to live again. Christ will judge whether they did deserve to die or not. If not, they will be resurrected into paradise on earth to live hundreds of years if they are careful to be obedient to God.
So, immorality and sin. Once you remove the incidents which were part of God's judgment - immoral actions usually are sin, and vice versa.
Another thing to not forget is this:
Many things were just described as they happened in the Bible; they weren't necessarily approved of by God!
In such cases the following shall happen:
Prov 11: 31 Behold, the righteous shall be repaid in the earth;
how much more the wicked and the sinner!
14 The unfaithful will be repaid for his own ways;
likewise a good man will be rewarded for his ways.
Ez 9:10 As for me also, my eye shall not spare, neither will I have pity, but I will bring their way on their head.
God is not partial -- what a human does shall come back to himself -- good or bad, there is no exception.
Rom 2: 6 who “will pay back to everyone according to their works:” 7 to those who by patience in well-doing seek for glory, honor, and incorruptibility, eternal life; 8 but to those who are self-seeking, and don’t obey the truth, but obey unrighteousness, will be wrath and indignation, 9 oppression and anguish, on every soul of man who works evil, to the Jew first, and also to the Greek.