Because Peter, in case you weren't aware, was a bit of a coward.
Cowards can still do the right things for the wrong reasons.
What did He preach?
Not pacifism.
Not "give up your weapons."
So what?
And what was the context of that command?
He was about to go to the cross. Resisting...