I've wondered at times why the Lord would command so many nations to be killed before Israel - until I read the sins of those countries and cities which are hinted at in the scriptures - in short their sins made them beyond degenerate and like Sodom and Gomorrah and about the only thing that could be done with them was to lay waste to them for their own eternal sake as so they didn't creep back up like a cancer or some noxious weed to corrupt the nation of Israel.
But what's interesting is the Lord gave certain lands to the Israelites, they were going to conquer and finish laying waste to them as they previously had, all by commandment and covenant of the Lord - and the Gibeonites knowing that they were on the list of people to be slaughtered - decided to trick the Israelites into making a covenant with them:
3 ¶ And when the inhabitants of Gibeon heard what Joshua had done unto Jericho and to Ai,
4 They did work wilily, and went and made as if they had been ambassadors, and took old sacks upon their asses, and wine bottles, old, and rent, and bound up;
5 And old shoes and clouted upon their feet, and old garments upon them; and all the bread of their provision was dry and mouldy.
6 And they went to Joshua unto the camp at Gilgal, and said unto him, and to the men of Israel, We be come from a far country: now therefore make ye a league with us.
7 And the men of Israel said unto the Hivites, Peradventure ye dwell among us; and how shall we make a league with you?
8 And they said unto Joshua, We are thy servants. And Joshua said unto them, Who are ye? and from whence come ye?
9 And they said unto him, From a very far country thy servants are come because of the name of the Lord thy God: for we have heard the fame of him, and all that he did in Egypt,
10 And all that he did to the two kings of the Amorites, that were beyond Jordan, to Sihon king of Heshbon, and to Og king of Bashan, which was at Ashtaroth.
11 Wherefore our elders and all the inhabitants of our country spake to us, saying, Take victuals with you for the journey, and go to meet them, and say unto them, We are your servants: therefore now make ye a league with us.
12 This our bread we took hot for our provision out of our houses on the day we came forth to go unto you; but now, behold, it is dry, and it is mouldy:
13 And these bottles of wine, which we filled, were new; and, behold, they be rent: and these our garments and our shoes are become old by reason of the very long journey.
14 And the men took of their victuals, and asked not counsel at the mouth of the Lord.
15 And Joshua made peace with them, and made a league with them, to let them live: and the princes of the congregation sware unto them. (Joshua 9).
There's a lot of lessons here.
One - the prophet of the Lord is not infallible - especially when he doesn't ask the Lord's counsel. A mortal man with the priesthood can still make mistakes - as was written by Nephi: "And now, if I do err, even did they err of old not that I would excuse myself because of other men, but because of the weakness which is in me, according to the flesh, I would excuse myself." - (1 Nephi 19:6)
But beyond this because they didn't ask what they needed to at the hands of the Lord...they now made an oath that put them at odds with the blessing the Lord had given them in terms of their inheritances - and they had a contradiction to deal with between the Lord and the oath they made which was sworn by the Lord.
I imagine there was some pride there in what they did - a feeling of satisfaction after their conquests and a bit of confidence at this point - which led to their being beguiled.
But the main lesson I learned was that we need to ask the Lord and consult with him in all our affairs always - not just now and then and not just the ones we think we need to. Am I smart enough not to consult with the Lord? No I am not. Am I smart enough to know what I should consult with him on while disregarding the other things?
Even Joseph Smith was warned at one point in a similar vein to Joshua: 37 But as you cannot always judge the righteous, or as you cannot always tell the wicked from the righteous, therefore I say unto you, hold your peace until I shall see fit to make all things known unto the world concerning the matter. (Doctrine and Covenants 10).
Pray always. Ask always. Check always.
We have the gift of the Holy Ghost and the priesthood...we need to use them.
Follow the guidance of the Lord.