When did Yehoshua command this?
Rashi: It was on the last day of mourning over Moshe.
Why did Yehoshua command this now?
Malbim: He had already spoken to Bnei Gad and Bnei Reuven and sent spies, and initially he intended to wait until they return. Now that Hashem spoke to him, he was strengthened and did not want to wait until the spies return.