Yes, they were supposed to kill or drive them out, but in the case of the Gibeonites they did not because of a rash oath.
If you read earlier in chapter 9, the Gibeonites deceived Joshua into believing they were a people from far away and not inhabitants of the land. As a result, Joshua makes an imprudent treaty with them:
The Israelites sampled their provisions but did not inquire of the Lord. Then Joshua made a treaty of peace with them to let them live, and the leaders of the assembly ratified it by oath.
Joshua 9:14-15 NIV
Later, when Joshua uncovers the deception and discovers they are neighbors we are told (v 18):
But the Israelites did not attack them, because the leaders of the assembly had sworn an oath to them by the Lord, the God of Israel.
So while the Lord had commanded the Israelites to drive out all the inhabitants of the land, they were deceived into making an oath before the Lord that prevented them from doing so in the case of the Gibeonites. They do, however, make themselves Joshua's servants and he presses them into forced labor for the alter. When the Amorites attack, Joshua defends them because of the treaty and because they are Israel's servants.
As to why the Amorites would have fought them, there were a number of different groups of people in Canaan and they were by no means all allies.