Deuteronomy 28 lists blessings and cursings.
If a nation “shalt hearken diligently unto the voice of the Lord thy God … all these blessings shall come on thee.”
But if a nation does not hearken to the voice of the Lord, “all these curses shall come upon thee,” including:
“The stranger that is within thee shall get up above thee very high; and thou shalt come down very low … and shall pursue thee, and overtake thee, till thou be destroyed.”
How did God judge Ancient Israel when it sinned?
He let the strangers invade: Philistines, Edomites, Moabites, Ammonites. Egyptians, Assyrians Babylonians, etc.
When Israel repented, God raised up deliverers.