Joshua 24:20
If ye forsake the LORD, and serve strange gods, then he will turn and do you hurt, and consume you, after that he hath done you good. If ye forsake the LORD, and serve strange gods, then he will turn and do you hurt, and consume you, after that he hath done you good.
Joshua 24:20 belongs to Joshua's closing loyal and faithful ringing testimony at the end of a life of steadfast integrity, given as his farewell address to Israel after the wars of conquest when the Lord had given the people rest from their enemies. It was spoken as he and one by one the old faithful sentinels who had crossed the Jordan were passing away. Those left included those who had transgressed and mourned at Bochim and a new generation who had not been accustomed to eat the bread from heaven.
The wider passage reviews God's care for Israel and warns against idolatry and ties with idolaters, including intermarriage, because these expose them to corruption and sin. The verse warns that if Israel forsakes the Lord and serves strange or other gods, He will turn and do them hurt and consume them with harm and ruin and loss of His favor and support, after all the good He has done them. Just as He has been faithful to do them good, so He will bring the threatened harm.
When Joshua gave the warning the people answered Nay but we will serve the Lord. He told them they were witnesses against themselves that they had chosen the Lord to serve Him, and they said We are witnesses. He then commanded them to put away the strange gods among them and incline the heart unto the Lord God of Israel.
The warning rests on God's character, for because He is perfectly truthful and holy, people cannot serve Him while continuing in sin but must repent and reform their lives to receive His favor. It exposes Israel's inability to secure God's favor by pledging obedience in their own strength, since the law condemns transgressors and gives no way to escape its claims, and reliance on personal righteousness cannot obtain pardon. Forgiveness and strength to obey come through faith in Christ and reliance on the merits of the promised Savior.
God's judgments after disobedience are meant to preserve His people from sin and bring them to repentance, and are no greater than necessary. The warning looks forward to the faithful steadfast souls passing away and their experience being forgotten, and the nation departing from God, corrupting themselves, mingling their worship with erroneous principles and haughty pride and love of display, and turning aside. The warning is to be applied personally, so that if a person turns from the Lord to serve other gods God will bring the threatened harm, and departing from God brings desolation.