I think the two statements are in contrast according to the time and context in which Jesus is speaking, and correspond to two commissions to evangelize which Jesus gave. In the first commissioning, early in their “training” the apostles were sent two by two, instructed to take nothing, no extra garment, no food, no sword, to go into the Jewish towns, not to gentiles, to preach, heal and drive out demons.
In the second commissioning, summarized in the great commission to go spread the good news to the whole world, baptizing all nations, also includes the instruction to gird the loins (which means a belt, actually a sword-belt) to buy a sword, put on sturdy sandals, take a satchel with everything one needs and prepare for a long journey, an arduous task, and prepare to meet difficulties and challenges. It is paraphrased in Ephesians in the Armor of God passage. I think the metaphorical meaning of sword as defense against persecution by truth (in the classical meaning of apologetics, by the way) is on th emark.