This is a good example of why we need a magisterium. It would seem on the surface that Jesus is teaching us that war is never justified. But this is not the case.
First, from a Catholic perspective we know this can’t be the case since the Church has always taught that lethal force and war can be justified when certain conditions are met. Concerning war, the Catechism of the Catholic Church states:
All citizens and all governments are obliged to work for the avoidance of war. However, “as long as the danger of war persists and there is no international authority with the necessary competence and power, governments cannot be denied the right of lawful self-defense, once all peace efforts have failed” (CCC 2308)
The Catechism goes on to list the conditions for legitimate use of military force in paragraph 2309. With regard to personal self-defense, the Catechism explains the Church’s teaching in paragraphs 2263-2267.
Second, I also think the context of Jesus’ statement precludes this idea that Jesus was condemning all violence. He says explicitly that he could call upon his legion of angels to defend him: “Do you think that I cannot appeal to my Father, and he will at once send me more than twelve legions of angels?” (Matt. 26:53). If all violence was bad, then why would Jesus insinuate he could possibly inflict it?
So, what are we to make of Jesus’ statement in the garden? Jesus was prohibiting Peter from using force in that particular circumstance. It was a circumstantial and temporary prohibition. Just as Jesus rebuked Peter for wanting to stop him from going to the cross in Matthew 16:23, Jesus does the same in the garden of Gethsemane. Peter’s actions served as an obstacle to Jesus’ mission to redeem the world. This is why Jesus tells Peter to put the sword back.
Jesus may have condemned the use of armed force that served as an obstacle to him fulfilling his role as savior of the world, but he was not condemning the use of armed force in an absolute sense. Therefore, this bible passage does not contradict the Church’s teaching on just war.