Joshua 11:18-20 leaves no room for free will if we take literally the statement that “it was of the Lord to harden their hearts." This problem comes up again and again in the anti-Canaanite narratives of Joshua, Deuteronomy and Kings where God instructs the Israelites to drive out the Canaanites and seems to endorse numerous actions that would be judged crimes against humanity today. But for some commentators, there is a justification.
The Sin of the Amorites
One way to deal with this problem takes us back as far is that time of Abraham, when God explains the reason for the Israelites having to go into Egyptian slavery.
Then the Lord said to Abram, “Know of a surety that your descendants
will be sojourners in a land that is not theirs, and will be slaves
there, and they will be oppressed for four hundred years; but I
will bring judgment on the nation which they serve, and afterward they
shall come out with great possessions...
And they shall come back here in the fourth generation; for the
iniquity of the Amorites is not yet complete.” (Gen. 15:13-15)
The theory here is that the Israelites could not lay claim to the land without justification in God's eyes. The justification lay in the sin of the Amorites - a widespread and exceedingly wicked people - which was not yet "complete" in the time of Abraham. However, by the time of Joshua, the Israelites were justified waging holy war to take the land of Canaan because the Amorites, who were themselves descendants of Noah's son Canaan (Gen. 10:16), represented that land.
Some scholars hold that the Philistines and Amorites are synonymous, and the "Amorites" of Gen 15 include all non-Israelite inhabitants of Palestine. They occupied several major cities including Jerusalem, Hebron, Jarmuth, Lachish, Eglon and various other places such as "hill-country of the Amorites" (Deut. 1:7-9) and the area north of Kadeshbarnea. There were also Amorites in Hazezon-tamar and Mamre (Gen. 14:7-13). Wellhausen ("Die Composition des Hexateuchs," ii. 341) believed that Amorites and Canaanites are synonymous expressions. "Amorites" refers to the Canaanites exterminated by Israel, while Canaanites refers to those living among the Israelites at the time of the kings.
The Jewish Encylopedia article goes on to say that Egyptian inscriptions call the land east of Phoenicia and north of Palestine "the land of the A-ma-ra." In the El-Amarna tablets the prince of the same region is called "Prince of Amurru." If all this is correct, the territory of the Amorites leaves very little room for the 'Canaanites' in the territory occupied by Israel. Moreover the terms sometimes seem to be used interchangeably.
If so, it was not that God hardened the hearts of the inhabitants; it was that their now-complete sin had made their hearts hard, and now the die had been cast against them. The author of Joshua expresses this awkwardly but the full measure of the "sin of the Amorites" is the underlying reality.
The above is not my personal view but I believe it deals with the OP question. My own opinion is that the narrative represents the view of the Deuteronomic histories in which the Israelites are supposed to the drive out the land's inhabitants because the latter are not God's people. This attitude raises many thorny ethical and philosophical questions for modern readers. Personally I have decided to accept them as beyond me, at least for now.