It was to counter the attack and plans of the enemies of Islam and Muslims. Islam orders Muslims to fight against the enemies who plan and try to attack Muslims, but to be peaceful with those who do not attack Muslims (Allah does not forbid you to deal nicely and kindly with those (Non Muslims) who fought not against you on account of religion nor drove you out of your homes (Sura 60, Verse 8).
Wassalam.