Even for well trained soldiers it isn't easy for those soldiers, except for sociopaths, to overcome their natural inclination not to kill another human being, even when that person has been designated as the "enemy" to kill. Of course, the generals, superior officers, and the military infrastructure are well aware of this, and are often able to mitigate such concerns, but demonizing the enemy in a manner in which that enemy is seen as subhuman or less than human, or basically anything other than a human, in which the killing of something that is not human is a far shorter hurdle for most to overcome. So too, the military is very good about impressing upon its soldiers the necessity of defending the honor of a nation, or its people, or its institutions and thereby helping to encourage those soldiers to do the necessary killing in order to defeat an avowed dangerous enemy.
All that being said, in actuality, the real reason, more times than not, that soldiers that are supposed to kill, actually get around to doing that killing against fellow soldiers or enemy combatants, has a lot to do with the fact that soldiers are placed into various units such as platoons, troops, regiments, squadrons, or batteries in which these groups of soldiers become identified with, for example, a particular platoon, which has been designated typically by a name and number such as the 54th Massachusetts Regiment, of which these soldiers know each other because they trained together, and are perhaps from the same hometown, or social background. This signifies that soldiers that are part of a platoon, for instance, have an obligation to do right by that platoon, and therefore when those soldiers are sent out to fight and to kill, those soldiers aren't just going out to fight and to kill as individual soldiers, but are part of a platoon that know each other, and therefore are far more inclined to take part in the killing of enemy soldiers, and to defend their fellow soldiers while doing so, because of their responsibility and their answerability to their fellow soldiers, over and above, the pertinent chain of command.
That is to say, soldiers that are in a group that has trained together, eaten together, and slept together, are a group of soldiers that have a vested interest in each other, and because of that vested interest in each other, they will do their duty, so as to not be disgraced or to letdown their fellow soldiers in the field of battle, even though, they, individually, may be conflicted about killing other soldiers or enemy combatants. This means, that most soldiers have a sense of duty not so much to their family, which cannot be cognizant of what is really going on in the field of battle, nor to their country which is too amorphous to actually get a hold of in the heat of a battle, nor necessarily to their chain of command, because that chain of command simply can't know for a certainty all that is going on in real time, but rather they recognize that their true duty is to their fellow soldiers of their group, that they will therefore do right by them, for they are fellow brothers in arms, and so it will be kill or be killed, and to do what must be done, so as to not suffer shame or disgrace, but receive instead, honor and respect from those that know them, best.