Joshua was privy to the same information that Moses had been given about the children of Israel before he died. Joshua, therefore, knew the truth, and that despite the people's vows to follow and to serve Jehovah, they would soon devolve to worshiping idols.
Here is what God revealed to Moses.
And the LORD said unto Moses, Behold, thou shalt sleep with thy
fathers; and this people will rise up, and go a whoring after the gods
of the strangers of the land, whither they go to be among them, and
will forsake me, and break my covenant which I have made with them.
(Deuteronomy 31:16, KJV)
Then my anger shall be kindled against them in that day, and I will
forsake them, and I will hide my face from them, and they shall be
devoured, and many evils and troubles shall befall them; so that they
will say in that day, Are not these evils come upon us, because our
God is not among us? (Deuteronomy 31:17, KJV)
And I will surely hide my face in that day for all the evils which
they shall have wrought, in that they are turned unto other gods.
(Deuteronomy 31:18, KJV)
Now therefore write ye this song for you, and teach it the children of
Israel: put it in their mouths, that this song may be a witness for me
against the children of Israel. (Deuteronomy 31:19, KJV)
For when I shall have brought them into the land which I sware unto
their fathers, that floweth with milk and honey; and they shall have
eaten and filled themselves, and waxen fat; then will they turn unto
other gods, and serve them, and provoke me, and break my covenant.
(Deuteronomy 31:20, KJV)
And it shall come to pass, when many evils and troubles are befallen
them, that this song shall testify against them as a witness; for it
shall not be forgotten out of the mouths of their seed: for I know
their imagination which they go about, even now, before I have brought
them into the land which I sware. (Deuteronomy 31:21, KJV)
Moses therefore wrote this song the same day, and taught it the
children of Israel. (Deuteronomy 31:22, KJV)
And he gave Joshua the son of Nun a charge, and said, Be strong and of
a good courage: for thou shalt bring the children of Israel into the
land which I sware unto them: and I will be with thee. (Deuteronomy
Therefore, Joshua knew what the people would do: He had it on good authority.