“when Joshua was by Jericho.” The chronology is general; God does not tell us exactly when this happened.
“And Joshua went to him.” God had told Joshua not to fear, and Joshua shows no fear in this situation. Also, it must have been clear to Joshua that this “man” was not a Canaanite, but Joshua apparently did not recognize the dress or appearance.