Leviticus 26:6
And I will give peace in the land, and ye shall lie down, and none shall make you afraid: and I will rid evil beasts out of the land, neither shall the sword go through your land. And I will give peace in the land, and ye shall lie down, and none shall make you afraid: and I will rid evil beasts out of the land, neither shall the sword go through your land.
The promise applies only if Israel walks in God's statutes and keeps and does His commandments and directions.
It stands in a chapter that sets out covenant blessings for obedience and curses for disobedience, warning that obedience brings God's favor while disobedience brings punishment.
When that condition is met, God gives peace and safety in the land, so the people lie down in rest and none makes them afraid.
That safety specifically means evil and dangerous beasts are rid out of the land and the sword does not go through it, so no enemy army invades.
The promise was spoken to Israel from the pillar of cloud together with other covenant blessings for obedience, including rain in due season, abundant harvests with enough food, victory over enemies, and God's tabernacle and presence among them as their God, making them the most powerful people on the earth.
Refusal to obey reverses the promise: in justice God must treat the disobedient as apostates, bringing punishment and curses instead of blessing, including failed crops and withdrawal of His blessing.
The Jews therefore could not claim the peace and safety while disobeying God, and the fact that enemies ruled over them showed they were under the covenant curse instead.