Oops, that should be 2 Samuel 24:15
God is a just God. No one is as just as Him. So, your reading above and the other examples you mentioned, all of them has long reasoning and explanation which basically related to what God and/ or men has said in “oath” towards each other, and also about God as the only true god as opposed to other gods who are not true. Worshiping other gods offends the True God.
In order to explain what happened in 2Samuel, we shall comeback to the time of Noah.
Noah get drunk and he did something that was shameful as a father of three sons. When he get sober, Noah realized that one of his son, Ham, have seen what he shouldn’t have. Noah was ashamed and angry, so he cursed Ham. Ham is the ancestor of Canaan. Please Read Genesis 9:18-27.
Long story short, by the time of Moses and the Kings, the Land of Canaan was a place of horrible practice of abominations (sorcery, witchcraft, idols worships) in which horrible sacrifices being paid to other gods (including human sacrifices and other horrible rituals that include eating human bowels and other horrible things).
So God said to Moses to enter this land and possess it.
Exodus 23
20.* "Behold, I am going to send an angel before you to guard you along the way and to bring you into the place which I have prepared.
And the way God help Moses and the people to possess the land was:
Exodus 23
28.* "I will send hornets ahead of you so that they will drive out the Hivites, the Canaanites, and the Hittites before you.
30.* "I will drive them out before you
little by little, until you become fruitful and take possession of the land.
31.* "I will fix your boundary from the Red Sea to the sea of the Philistines, and from the wilderness to the River Euphrates; for I will deliver the inhabitants of the land into your hand, and you will drive them out before you.
One thing that God asked them to be cautious about:
Exodus 23
32. "You shall make no covenant with them or with their gods.*
33.* “They shall not live in your land, because they will make you sin against Me; for if you serve their gods, it will surely be a snare to you.”
Long story short, Moses never enter the Canaan land because he was fearful so he wanders in the dessert for 40 years. After Moses died, then Joshua son of nun begin to conquer the land little by little as God asked hum to. Please read Joshua 24:12-14.
By the era of the Judges, Israel has settled in the land, but they never really drive the other nations out, as asked by God, instead they tax them. Because of this tax, God says, from then on, He will not drive the other nations. Instead, Israel has to live side by side with them.
Judges 1
28 But when the Israelites grew stronger, they exacted taxes from the Canaanites who stayed in their place.
29 Neither the tribe of Ephraim expel the Canaanites who lived in Gezer
30 nor did the tribe of Zebulun drive out the inhabitants of Kitron and Nahalol. These Canaanites lived among them, but had to pay taxes to them.
Judges 2
2 but You shall not make covenant with with the Canaanites and shall destroy their altars. But you have not obeyed…
3 Now, I will not drive out these nations before you. They shall be your oppressors and their gods shall be a trap for you
Please read Wisdom12 in which the above passages being explained in detail with regard why God did what He did.
Wisdom 12 (“You” in this passage addresses God, please read the whole chapter12)
15 You are just and you rule all with justice, and **had you condemed those who should not be punished, you would have
misused your power.
19 In this way, you have taught your people that a righteous person must love his
human fellows; you also have given your people cause for hope by prompitng them to repent of their sin.
After the above long explanation: I recommed you to read the bible in contextual manner. Use the bible search to find out what happened. It’s actually not an easy thing to do if you’re not familiar with the teaching yet.
I recommend that you read the book of Genesis first, and then jump to Gospel of Luke and John first (becasue these two gospels covers almost all the content of the 4 gospels). After this, you may read The book of Job (since you seem to have so many questions similar to Job’s questions), and find out how Jesus birth, life and ressurection answers Job’s (and his friends) questions. Job is not an easy book to understand on its own, but it is much easier to read (not necessarily to understand

) compared to other old testament books, in the light of the Gospels.**