A king may only initiate an optional war with the authorization of the Great Sanhedrin, as derived from the verse describing Joshua's appointment, where "he" refers to the king, "the priest anointed for war" represents the priestly advisor, and "all the congregation" denotes the Sanhedrin.
אֵין מוֹצִיאִין וְכוּ׳. מְנָהָנֵי מִילֵּי? אָמַר רַבִּי אֲבָהוּ: דְּאָמַר קְרָא ״וְלִפְנֵי אֶלְעָזָר הַכֹּהֵן יַעֲמֹד״. ״הוּא״ – זֶה מֶלֶךְ, ״וְכׇל בְּנֵי יִשְׂרָאֵל אִתּוֹ״ – זֶה מְשׁוּחַ מִלְחָמָה, ״וְכׇל הָעֵדָה״ – זֶה סַנְהֶדְרֵי.
§ The mishna teaches that the king may bring the nation out to an optional war only on the basis of a court of seventy-one judges, i.e., the Great Sanhedrin. The Gemara asks: From where is this matter derived? Rabbi Abbahu says: It is as the verse states with regard to the appointment of Joshua: “And he shall stand before Elazar the priest, and he shall ask counsel of the Urim before the Lord; by his word they shall go out, and by his word they shall come in, he and all of the children of Israel with him and all of the congregation” (Numbers 27:21). Rabbi Abbahu analyzes the end of the verse. With regard to the word “he,” this is the king, referring to Joshua and to any other leader who brings the nation out to war. With regard to the word “him” in the verse “And all of the children of Israel with him,” this is the priest anointed for war, who was anointed specially to stand and instruct the people before the war (see Deuteronomy 20:2). “And all of the congregation”; this is the Sanhedrin. Consequently, the king can embark on an optional war only if the Great Sanhedrin is present and grants authority to him.