'And fight in the way of Allah those who fight you.' This was before they were commanded to fight the polytheists entirely, so they would not fight anyone except those who fought them. 'And do not transgress,' meaning: in your warfare, by fighting those who have not fought you. Then, He commanded the fighting of them in Surah Bara'ah.
﴿وَقَاتِلُوا فِي سَبِيلِ اللَّهِ الَّذِينَ يقاتلونكم﴾ وَذَلِكَ قبل أَن يؤمروا بِقِتَال الْمُشْركين كَافَّة؛ فَكَانُوا لَا يُقَاتلُون إِلَّا من قَاتلهم ﴿وَلا تَعْتَدُوا﴾ يَعْنِي: فِي حربكم؛ فتقاتلوا من لم يُقَاتِلُوكُمْ، ثمَّ أَمر بقتالهم فِي سُورَة بَرَاءَة.