Sotah, Chapter Eight, Mishnah Seven
Our mishnah teaches that the rules spelled out in our chapter do not apply to all types of war. In certain types of war, all of Israel must go out to battle, even a bride and groom from their wedding. There are two different opinions as to what types of war mandate the participation of all.
1) To what this apply? To a voluntary war, but in a war commanded [by the Torah] all go out, even a bridegroom from his chamber and a bride from her canopy.
2) Rabbi Judah says: to what does this apply? To a war commanded [commanded by the Torah], but in an obligatory war all go out, even a bridegroom from his chamber and a bride from her canopy.
Section one: According to the first opinion, the preceding rules apply to a voluntary war, which is a war to expand the borders of Israel. In such a war some people receive exemptions. However, in a defensive war, which this opinion calls a war commanded by the Torah, all must go out and fight.
Section two: Rabbi Judah has a different opinion. A defensive war, even though it is a mitzvah (commanded), does not mandate the participation of all. However, an obligatory war, such as the conquest of the land by Joshua or the perpetual war against Amalek, requires the participation of all. These wars are obligatory because there are verses in the Bible that directly mandate them.
I have interpreted the mishnah according to Albecks commentary. There are other interpretations in the Talmud and in the commentaries concerning the differences between the two opinions.
Note, that at times mitzvah is opposed to obligation. For instance, there is a mitzvah that if one divorces his wife, he must do so with a get. However, there is certainly no obligation to divorce.