As Bishop stated:
Customary international humanitarian law has 2 cases of miltary non-combatants:
Rule 3. All members of the armed forces of a party to the conflict are combatants, except medical and religious personnel.
Source: IHL Databases
"Party to the conflict" is the important part of this. In your example, the Fort Hood shooting, there was no "armed conflict" that the military personnel involved were party to as far as the definition under international law goes.
From that link (emphasis mine):
Non-international armed conflicts, according to common article 3 of the Geneva Convention, are ‘armed conflicts that are non-international in nature occurring in one of the High contracting parties’ (Geneva Convention, common article 3, 1949). This means that one of the parties involved is nongovernmental in nature. However, common article 3 also states that it does not apply to other forms of violence such as riots, isolated and sporadic acts of violence.
Which invalidates the Fort Hood shooting as an armed conflict, it being an isolated act of violence, and thus the military personnel involved were not combatants.
So to answer your question, military personnel are not combatants when they are not actively engaged in an "armed conflict" as defined above. This, however, does not make them invalid targets for an enemy to attack under international law. Military personnel are legitimate military targets under international law unless they are Hors de Combat (emphasis mine, relevant to comments)
Protocol I to the Geneva Conventions defines:
A person is "hors de combat" if:
(a) he is in the power of an adverse Party;
(b) he clearly expresses an intention to surrender; or
(c) he has been rendered unconscious or is otherwise incapacitated by wounds or sickness, and therefore is incapable of defending himself;
provided that in any of these cases he abstains from any hostile act and does not attempt to escape.