God has not contradicted himself. If you or anyone thinks so, you only show that you do not understand. Would-be contradictions come from misinterpretation.
Jos 6 And
the LORD said unto Joshua, See, I have given into thine hand Jericho, and the king thereof, and the mighty men of valour.....all the people shall shout with a great shout; and the wall of the city shall fall down flat, and the people shall ascend up every man straight before him.
Joshua recorded, (bible) 'the people went up into the city, every man straight before him, and they took the city.
And they utterly destroyed all that was in the city, both man and woman, young and old, and ox, and sheep, and ass, with the edge of the sword'.
Josh 8 Then
the Lord said to Joshua, “Do not be afraid; do not be discouraged. Take the whole army with you, and go up and attack Ai. For I have delivered into your hands the king of Ai, his people, his city and his land.
You shall do to Ai and its king as you did to Jericho and its king.
THEN from the same Source, the Lord, written with His finger, said, 'Do not kill'
kill - râtsach
A primitive root; properly to dash in pieces, that is, kill (a human being), especially to murder: - put to death, kill, (man-) slay (-er), murder (-er).
And 40 years later that's what God told Joshua to do. Dash in pieces with the sword, men, women and children.
No interpretation here just scripture. God's word (command) written down (given to Moses) and God's word (command spoken to Joshua).
What God spoke contradicted what He wrote.
Personally I'm fine with this.