What is the meaning of the oft-repeated phrase לצאת ולבוא as in Deuteronomy 31:2 ? I realize it means "to conduct business" or "to lead", but I was hoping for more of a deep dive (does it come from a shepherding metaphor?)
R' Samson Raphael Hirsch, in his commentary on Deuteronomy 31:2, calls "לצאת ולבוא" "the general term used for the public efficient activity of national leadership," and points us to his full workup of the term in his commentary on Numbers 37:17, where Moses uses similar terminology in asking God to appoint his successor:
אֲשֶׁר־יֵצֵ֣א לִפְנֵיהֶ֗ם וַאֲשֶׁ֤ר יָבֹא֙ לִפְנֵיהֶ֔ם וַאֲשֶׁ֥ר יוֹצִיאֵ֖ם וַאֲשֶׁ֣ר יְבִיאֵ֑ם וְלֹ֤א תִהְיֶה֙ עֲדַ֣ת יְהוָ֔ה כַּצֹּ֕אן אֲשֶׁ֥ר אֵין־לָהֶ֖ם רֹעֶֽה׃
who shall go out before them and come in before them, and who shall take them out and bring them in, so that the LORD’s community may not be like sheep that have no shepherd.”
There, R' Hirsch also explains that "לצאת ולבוא" refers to leadership activities in general, and not [only] to military leadership. He brings two other Biblical usages of this construct as evidence:
In I Kings 3:6-9, when Solomon requests that God grant him wisdom, particularly to be able to judge the people (v. 9), he points out (v. 7)
וְאָֽנֹכִי֙ נַ֣עַר קָטֹ֔ן לֹ֥א אֵדַ֖ע צֵ֥את וָבֹֽא׃ ...
... but I am a young lad, with no experience in leadership.
In Joshua 14:11, Caleb explicitly treats "לצאת ולבוא" as separate from military endeavors:
עוֹדֶ֨נִּי הַיּ֜וֹם חָזָ֗ק כַּֽאֲשֶׁר֙ בְּי֨וֹם שְׁלֹ֤חַ אוֹתִי֙ מֹשֶׁ֔ה כְּכֹ֥חִי אָ֖ז וּכְכֹ֣חִי עָ֑תָּה לַמִּלְחָמָ֖ה וְלָצֵ֥את וְלָבֽוֹא׃
I am still as strong today as on the day that Moses sent me; my strength is the same now as it was then, for battle and for activity.
Finally R' Hirsch interprets the "going out" and "coming in," respectively, as setting a good example in the public and the private spheres, thereby influencing people to "faithfully fulfill all public and private duties."
א"ר שמואל בר נחמני א"ר יונתן לצאת ולבוא בדברי תורה מלמד שנסתתמו ממנו שערי חכמה
R. Samuel b. Nahmani said in the name of R. Jonathan: [It means] to ‘go out and come in’ with words of Torah, thus indicating that the gates of wisdom were closed off to him.
The meforshim show that the order gives an indication of how one should lead. First, to "exit" or "go out". To lead the people out to war or to whatever activities are necessary. It is like the principle of the IDF that leaders lead. After they have led the people in "going out" to perform the necessary tasks, they lead the people back in (they "come"). They show the people how to live in peace and tranquility within Eretz Yisrael.
This is from memory of various shiurim. I do not have the citations in front of me.