Joshua called for a meeting of Israel’s leaders (23:1,2), reminded them of how good God had been to them (v.3-5), and told them that “therefore” they should have the “courage” to obey God and not turn to the right or to the left(v.6).
That’s a Bible idiom similar to making a beeline. Bees move right and left to gather nectar, but once they are full, they make a beeline for the hive. And once you know how spiritually full God made you in Christ, it’s easier to serve Him without turning to the right or left to the world’s temptations.
It’s natural not to make a beeline, but God can overcome what comes natural, as he did when the Philistines stole the ark. God cursed them with hemorrhoids, but they weren’t sure if God was judging them. So they hooked two cows to a cart, put the ark on it, and locked their calves up. They knew the cows would naturally stick around to nurse them. They learned He was judging them when instead He over-came their natures (cf.Isa.11:6,7) and the cows took the ark home without turning right or left (ISam.6:12). And God can overcome your sinful nature to serve Him as well.
God particularly wanted the Jews to serve Him by steering clear of pagans (Josh.23:7), because that led to worshipping their gods. The best way to do that was to not even “mention” their names. I know Christians say you should learn about Allah to witness to Muslims, but God told the Jews not to learn how the heathen worshipped (Deut.12:30)—or even mention their gods (Ex.23:13;Ps.16:4). Christians won’t stop, but God will stop them in the kingdom (Hos.2:17).
You see, when God remarries Israel (Rev.19:7,8), He isn’t going to want to hear the names of His wife’s former lovers any more than any husband would, and we see this forbid-ding of mentioning their names typified here. You needn’t read the Book of Mormon to know how to witness to a Mormon. If you have a Bible, you have everything you need to do that good work (IITim.3:16,17). God wants you “simple” concerning the evil in religious books (Rom.16:17).
Joshua told them not to “swear by” those gods (23:7) because men “swear by the greater” (Heb.6:16). So if they swore by Baal to convince a pagan something was true, they’d be admitting Baal was greater than God. That sometimes led to forsaking God completely (Jer.5:7), but it usually led to sinfully worshipping both (Zeph.1:4,5). This could be avoided if they’d “come not” at pagan women (Josh.23:7), i.e., marry them (cf.Ex.19:15), and instead, “cleave” to God (Josh.23:8cf.Gen.2:24;Deut.10:20).
To motivate them to cleave to God, Joshua warned them that God will punish them if they don’t (Josh.23:9-13). When verse 12 says not to “go in unto” their women, that’s another warning not to marry them (cf.Ruth 4:13). The wisest man in the world disobeyed this warning and paid the price (IKi.11:1-5). If you marry someone who worships false gods, when you’re “old” like Solomon, you’ll end up worshipping Allah, or Buddha—or more subtle gods, like the god of materialism. If “covetousness…is idolatry” (Col.3:5), then materialism is a religion you want to avoid too. You may never literally sacrifice your children to materialism (cf.Ps. 106:34-39), but letting them grow up as materialistic as your unsaved spouse condemns them to the slow death of a lifetime of covetousness.
To further motivate his people, Joshua reminds them that not one good thing of all God promised to give them had failed (Josh.23:14cf.21:43). But they were under the law that said God would curse them if they disobeyed Him (Lev.26), so Joshua ends with a warning about that (Josh.23:15,16). But under grace, all God’s promises are unconditional (IICor.1: 20). Paul promised to return to Corinth but couldn’t, so they said he took his promises lightly. Paul used that to say that the Lord will keep His promise to return for us, and not one good thing of all He’s promised us will fail in heaven!