According to 2 Peter 3:9, God does not want anyone to perish but wants all people to come to repentance. Nevertheless, he does not show mercy to everyone. He hardens the hearts of some people leaving them in their sinful rebellion (e.g., Pharaoh and the Canaanite kings) while he softens the hearts of others and brings them to true faith and repentance (e.g., Rahab). Why God chose to have mercy on Rahab (and Gibeon) but not on the other Canaanites, we are not told. We know that his decision to show mercy is not based on any good within human beings, as if some people are more worthy or deserving of his grace (e.g. Deuteronomy 7:6–11), it is based only on his sovereign choice to love a people of his choosing (e.g. Ephesians 1:3–14).
As a result, we must be content with the teaching of Scripture where God tells us, I will have mercy on whom I have mercy, and I will have compassion on whom I have compassion
(Romans 9:15; cf. Exodus 33:19).
20 For it was the LORD’s doing to harden their hearts that they should come against Israel in battle, in order that they should be devoted to destruction and should receive no mercy but be destroyed, just as the LORD commanded Moses.