It's right there in the text. The purpose of the sword --- or one of the purposes --- was to fulfill the prophecy that he would be numbered with the transgressors. That would have served as corroborating evidence that he was a rebel and a king opposed to Caesar, as well.
So, both --- the fact that his followers were (ridiculously lightly) armed, and the false charge that Jesus was a revolutionary --- added up to Jesus being "numbered with the transgressors."
BTW, there is some controversy as to whether it was unlawful for non-Roman citizens to even possess swords. It's plausible that Jesus knew they would be arrested because of having swords.
In other words, the swords were not there for self-defense: they were there to provoke arrest.
I've read opinions for and against, but I don't know if it can be answered definitively.
Actually, the passage structure and Greek structure tells a different story.
Christ is contrasting what will come from what existed before.
(Specifically, it is a counter-point/point structural marker. Verse 35 when I sent you out you didnt lack *anything*../.. verse 36 but now)
How will it differ?
First, Christ answers Peters boast by showing the intensity of the persecution to come, Jesus answered, I tell you, Peter, before the rooster crows today, you will deny three times that you know me. It will be that bad.
Then, Christ names the items, including the sword, As necessary now, in contrast to the situation that existed when the disciples had been sent out before.
Then Jesus asked them, When I sent you without purse, bag or sandals, did you lack anything?
Nothing, they answered.
The Greek structural focus of the supporting marker in sentence, is that Christ will be numbered with transgressors and this fulfillment of prophecy must happen and would change everything.
That change is positioned in Greek sentence structure as the supporting justification as to why the disciples needed these items including a sword.
This situation is a 180 degree turn from before, when He was welcomed and his disciples commanded respect.
(I mentioned earlier that it was not the presence of swords that Christ was charged with, but opposing Ceasar. )
Best