Nowadays, religiously observant Israeli soldiers fight on the Sabbath when necessary. However, writes Shlomo Brody, Jewish law was not always so clear in this regard:
The book of Maccabees records that in 167 BCE, the Seleucids initially succeeded in defeating Jewish pietists by attacking them on Shabbat and slaughtering them, because of their lack of resistance. . . . [S]imilar incidents had occurred in the 4th century BCE with the conquest of Jerusalem by Ptolemy Lagos and would occur later with Pompey’s conquest of the Temple Mount in 63 BCE.
Scholars have long debated the motivation behind [the] lack of resistance. [According to some interpretations], this attitude reflects the practices of the Sadducees and other similar sects who refused to violate Shabbat even in the case of warfare. Indeed, explicit testimony to this effect is found in the [apocryphal] book of Jubilees and in a few texts attributed to the Dead Sea sects.
According to 1 Maccabees, this outlook was rejected by the Hasmoneans. Mattathias, [the leader of the revolt], declared, “If any man comes against us on the Sabbath day, we shall fight against him and not all die as our brothers did in their hiding places.” This sentiment was not accepted by many Jewish sects, but was certainly endorsed by rabbinic and Pharisaic texts. . . .
Other texts further assert that the rabbis, led by the famous sage Shammai, declared that Jews can even initiate warfare on Shabbat for the sake of protecting or conquering the land of Israel. . . .
This attitude should not be taken for granted. As we see from antiquity, a fundamentalist outlook might assert that Shabbat should be kept at all costs. The Hasmoneans and ancient rabbis taught us, however, that sometimes the Sabbath must be desecrated, alas, so that the Jewish people can observe many more Sabbaths in the future. We should live for Shabbat, but not die for it.