Question: Just before his arrest and death Jesus told his disciples to sell their clothes and use the money to buy themselves swords (see Luke 22, verses 35 - 38). Why were the disciples told to buy such weapons?
Answer: First, let us take a look at the verses you mentioned that concern Jesus and his disciples buying swords.
And He (Jesus Christ) said to them (his twelve disciples), "When I sent you (on training missions) without money bag, knapsack, and sandals, did you lack anything? . . . But now . . . he who has no sword, let him sell his garment and buy one . . . For the things concerning Me have an end."
So they (the disciples) said, "Lord, look, here are two swords." And He said to them, "It is enough" (Luke 22:35 - 38, NKJV).
https://www.biblestudy.org/question/why-did-jesus-tell-disciples-to-buy-swords.html