1)
When did Yehoshua command this?
1.
Rashi: It was on the last day of mourning over Moshe.
2)
Why did Yehoshua command this now?
1.
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.