The problem is that we often compartmentalize scripture through division into the Old and New Testaments, and as a result treat God as different in each, when in fact, He is not. Evidence that the Lord is a God of grace persists from His favor over the house of Israel during Joseph's reign in Egypt, to his intention of fulfilling his covenants with the three patriarchs. The first and foremost of these, the Abrahamic covenant (Gen. 12), is based on unconditionality, meaning no action was required from Abraham.
God, as omniscient Spirit, knows Abraham's heart and allows him to negotiate for Sodom and Gomorrah on behalf of the righteous. As much as the negotiation sounds like a bartering deal at a flea market, a critical look at the text demands not an emphasis on numbers (v. 23-32), but the Lord's impartation of grace and love for the righteous in the two cities and more important, the establishment of His will for Abraham.
Secularist scholars may look at this passage and infer that there are two gods here-- one of vengeance and retribution, another of reason and compassion. The dilemma is false at best because it ignores the fundamental characteristic of God as both just and gracious and also a God of immutability; in other words He is unchanging. The Lord's sovereignty and omniscience demands that He knows exactly what He plans to do with Sodom and Gomorrah, regardless of what Abraham pleads. However, Abraham's intercession is ordained by God to accomplish His will. Here's some good analysis on God-moving prayer from Ligonier Ministries:
Understanding that God knows the end from the beginning, has decreed “whatsoever comes to pass” (WCF 3.1), and is sovereign over all actually gives us hope that the Lord does indeed respond to prayer. These truths are not to make us fatalistic and keep us from praying. God has not revealed to us His sovereign decrees. According to Deuteronomy 29:29, they are hidden from us and belong to Him alone. Still, what the Lord has told us is for us to know forever, and He has revealed in Scripture that He uses our prayers to accomplish His will. Our prayers move Him to act, which is, of course, due to the fact that He ordains even our intercession. But that is not our focus in prayer. Instead, we are to implore Him to act, knowing how He delights to hear from us and to grant our requests as they align with His purposes (1 John 5:14).Abraham's intercession sets the groundwork for our prayer to God. Our Lord Jesus Himself prayed to the Father: "...not my will, but Yours be done" (Luke 22:42).