Again context! Context!
Quran verse 9:4
"As for the polytheists who have honoured every term of their treaty with you and have not supported an enemy against you, honour your treaty with them until the end of its term. Surely Allah loves those who are mindful ˹of Him˺."
That means Muslims must keep the truce they have agreed with the polytheists, when they have kept their side of the deal.
The Quran 9:5
"But once the Sacred Months have passed, kill the polytheists ˹who violated their treaties˺ wherever you find them,1 capture them, besiege them, and lie in wait for them on every way. But if they repent, perform prayers, and pay alms-tax, then set them free. Indeed, Allah is All-Forgiving, Most Merciful."
Here Allah gives Muslims the permission for Muslims to only fight the polytheists who broke the deal, killing Muslims, raiding Muslim caravans etc, and to do it outside the Sacred Months.
Next comes the best part in Quran 9:6
"And if anyone from the polytheists asks for your protection ˹O Prophet˺, grant it to them so they may hear the Word of Allah, then escort them to a place of safety, for they are a people who have no knowledge."
So what is the issue you have here?