The rules of “just war” were not developed in courts by religious advisers keen to justify war. Rather, the tradition took shape largely in the setting of the confessional. It was codified in canon law by priests who wanted to limit the brutality of war and who were responding to a very practical question: Should knights returning from the battlefield be allowed to partake of the Eucharist? “Just war” precepts were applied to determine what sorts of penance soldiers should be made to perform before being fully readmitted to the Body of Christ.
For additional perspectives on this issue, go here.