Joshua is being handed a job he did not ask for, following a man nobody could follow. Moses is dead. The people are the same people who complained for forty years. The land ahead is occupied. Into that, God says the same thing four times in nine verses: be strong and of a good courage.
Repetition like that usually means the hearer is not feeling it. God is not congratulating Joshua on his nerve; he is issuing courage as an instruction, which implies it is something that can be chosen rather than merely felt. The command comes with a reason attached every time — for the Lord thy God is with thee whithersoever thou goest.
That is the load-bearing clause. Joshua's courage is not confidence in his own leadership, his army, or his read of the situation. It rests entirely on a presence he cannot see and did not arrange. He is told not to be afraid neither be thou dismayed — a word that means shattered, broken apart. Fear may visit; being broken by it is what he is warned against.
Notice too what God tells him to do with his days: keep the book of the law in his mouth, meditate in it day and night. Courage here is not a burst of feeling before a battle. It is fed slowly, by attention to what God has actually said.