What should a Muslim do if he's currently serving in the military and is required to fight a war against a Muslim nation or required to kill Muslims in the course of his duty for his nation, since it is a capital Haram to kill one's brother.
Such a Muslim must stop working or helping this army immediately. In case it is impossible, he must avoid providing direct participation in killing others. The Prophet (peace be upon him) is reported to have said: “Do not (become infidels) revert to disbelief after me by striking the necks (cutting the throats) of one another (killing each other).” (Al-Bukhari)
In another Hadith narrated by Al-Ahnaf Ibn Qays (may Allah be pleased with him) quotes the Prophet (peace and blessings be upon him) as saying: “If two Muslims meet with their swords (attacking each other) then (both) the killer and the killed one are in the (Hell) Fire.’ I (Al-Ahnaf Ibn Qays) said, ‘O Allah’s Messenger! It is all right for the killer, but what about the killed one?’ He said, ‘The killed one was eager to kill his opponent.’” (Al-Bukhari)
Even, the Prophet (peace and blessings be upon him) has forbidden a Muslim to direct a weapon against his brother; he should not even try to joke with that. Here, the question arises: what about a Muslim recruited in the army of a non-Muslim country that is at war with Muslims? Such helpless Muslim soldier has no choice but to yield to the orders of his army commanders and he has no right to say ‘No’ or ‘Why’? This is a well-known military system worldwide.
The opinion, which is more akin to the sound juristic view here, is that a Muslim shouldn’t indulge in a war against his fellow Muslim brothers, and he may justify his position by asking for a leave or (a temporary) exemption from the military as the true conscience of a Muslim dictates that he shouldn’t indulge in killing a fellow Muslim brother without a justifiable reason. However, if there is no way but to participate, then a Muslim can join the rear to help in military service (i.e. not to participate in face-to-face confrontation).
Allah Almighty knows best.