Joshua 23:12

Else if ye do in any wise go back, and cleave unto the remnant of these nations, even these that remain among you, and shall make marriages with them, and go in unto them, and they to you:

Joshua spoke these words in his farewell address to Israel after the wars of conquest had ended and the Lord had given Israel rest from its enemies. The warning was against turning back from loyalty to God and cleaving to the remnant of the Canaanite and heathen nations that remained among Israel. Making marriages with them and going in unto them and receiving them in return would expose Israel to the corrupting influence of their idolatry and abominations and lead Israel away from God.

The principle taught is to avoid even the borders of sin, for even to enter upon that border places a person in danger of being engulfed in sin and ruin. Joining with those nations would forfeit God's protecting care. The very nations joined would then become instruments of punishment, bringing snares and scourges and thorns until Israel perished from the land.

Departing from God brings desolation and ruin. As God had kept His promises to Israel, so He would also carry out His warnings, showing Himself faithful to both promises and warnings. The warning was given not only to Israel as a nation but to each person individually. It applies to the choosing of close companions or marriage partners who reject God, since such ties can begin a course of backsliding that leads to apostasy.