I’d recommend reading the full chapter in which those verses are in. Reading the full chapter will give you more context by giving more information on the full situation. With more context comes more understanding. People have a bad habit of taking out single verses to justify their position.
Luke 22:36. That hath not, &c. Whilst the apostles are contending for prerogative, he reminds them that now is the time of danger and slaughter; for I, your Master, (says he) shall be led to a dishonourable death, and reputed among the wicked: as all which hath been foretold of me shall have their end; that is, be fulfilled. Wishing also to insinuate the violence of the assaults they themselves will have to sustain, he mentions a sword; but does not reveal all, lest they should be too much alarmed; nor does he entirely suppress the mention of it, lest sudden attacks might overpower them, had they not been forewarned. (Theophylactus)
Matt 26:52. Shall perish by the sword. This was not to condemn the use of the sword, when employed on a just cause, or by lawful authority. Euthymius looks upon it as a prophecy that the Jews should perish by the sword of the Romans. (Witham) — Our divine Saviour would not permit this apostle to continue in his pious zeal for the safety of his Master. He says to him: put up thy sword. For he could not be unwilling to die for the redemption of man, who chose to be born for that end alone. Now, therefore, he gives power to his implacable enemies to treat him in the most cruel manner, not willing that the triumph of the cross should be in the least deferred; the dominion of the devil and man’s captivity in the least prolonged. (St. Leo)