Preemptive Strikes
אין מוציאין כו': מנהני מילי אמר ר' אבהו דאמר קרא (במדבר כז, כא) ולפני אלעזר הכהן יעמוד
§ 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).
אֵין הַמֶּלֶךְ נִלְחָם תְּחִלָּה אֶלָּא מִלְחֶמֶת מִצְוָה. וְאֵי זוֹ הִיא מִלְחֶמֶת מִצְוָה זוֹ מִלְחֶמֶת שִׁבְעָה עֲמָמִים. וּמִלְחֶמֶת עֲמָלֵק. וְעֶזְרַת יִשְׂרָאֵל מִיַּד צָר שֶׁבָּא עֲלֵיהֶם. וְאַחַר כָּךְ נִלְחָם בְּמִלְחֶמֶת הָרְשׁוּת וְהִיא הַמִּלְחָמָה שֶׁנִּלְחָם עִם שְׁאָר הָעַמִּים כְּדֵי לְהַרְחִיב גְּבוּל יִשְׂרָאֵל וּלְהַרְבּוֹת בִּגְדֻלָּתוֹ וְשִׁמְעוֹ:

A priori, the king does not go to fight other than a War of Mitzvoh (Mandatory War). What is a War of Mitzvoh? This is the war against the Seven Nations30Aboriginal to Eretz Yisroel. or the war against Amalek or any war to assuage Israel of a persecutor. After this, he may fight Discretionary Wars which are those wars he conducts against the other nations in order to enlarge the borders of Israel, and increase his renown and reputation31So that the Gentiles will be afraid of us and won’t bother us..

אמר רב יהודה אמר רב נכרים שצרו על עיירות ישראל אין יוצאין עליהם בכלי זיינן ואין מחללין עליהן את השבת תניא נמי הכי נכרים שצרו וכו' במה דברים אמורים כשבאו על עסקי ממון אבל באו על עסקי נפשות יוצאין עליהן בכלי זיינן ומחללין עליהן את השבת ובעיר הסמוכה לספר אפילו לא באו על עסקי נפשות אלא על עסקי תבן וקש יוצאין עליהן בכלי זיינן ומחללין עליהן את השבת .

Rav Judah stated in the name of Rav: "If foreigners besieged Israelite towns, it is not permitted to sally forth against them or to desecrate the Sabbath in any other way on their account," and a Tannaitic source teaches the same thing. This, however, applies only where they came for the sake of money matters, but if they came with the intention of taking lives the people are permitted to sally forth against them with their weapons and to desecrate the Sabbath on their account. Where the attack, however, was made on a town that was close to a frontier the loss of which would constitute a strategic danger to other parts of the country], even though they did not come with any intention of taking lives but merely to plunder straw or hay, the people are permitted to sally forth against them with their weapons and to desecrate the Sabbath on their account.

אמר רבא מלחמות יהושע לכבש דברי הכל חובה מלחמות בית דוד לרווחה דברי הכל רשות כי פליגי למעוטי עובדי כוכבים דלא ליתי עלייהו מר קרי לה מצוה ומר קרי רשות נפקא מינה לעוסק במצוה שפטור מן המצוה

Rava said: With respect to the wars that Joshua waged to conquer Eretz Yisrael, all agree that they were obligatory. With respect to the wars waged by the House of King David for the sake of territorial expansion, all agree that they were elective wars. When they disagree, it is with regard to preventative wars that are waged to reduce the gentiles so that they will not come and wage war against them. One Sage, Rabbi Yehuda, called this type of war a mitzva, and one Sage, the Rabbis, called it an elective war. There is a practical difference between these opinions with respect to the principle: One who is engaged in a mitzva is exempt from performing another mitzva. According to Rabbi Yehuda, one fighting in this kind of war is exempt from performing another mitzva.