God's justice is according to His righteousness, His holy character. Psalm 119:172 defines righteousness, stating "All Your commandments are righteousness." Those commandments reflect in writing the character of God.
What God does is always consistent with who and what He is, and what He has written. His righteousness is absolute purity. He is utterly incapable of an unholy, unrighteous, unjust act. For God to act unfairly, He would simply have to cease being God. It is totally impossible for Him to commit an injustice.
When Abraham uses the word "righteous" in verse 23, he is not saying, "Would You destroy the sinless with the wicked?" He means people who, through their fear of God and being conscientious, have kept themselves free from the iniquity of Sodom and Gomorrah. Abraham's concern was that there were people in the city we might consider to be really good citizens. They were not sinless, but if there was a fear of God in them, maybe they were trying with all their might to obey God, but they were caught up simply in being in the environment which God had decided He was going to destroy.
God does not always act with justice; sometimes He acts with mercy. That is what He did with Lot and his family. God acted with justice against the city because it was so corrupt, so evil, so filled with sin that it even offended God's sense of what is right and wrong. It even offended God's patience, His longsuffering. And so in justice He wiped the city off the map, but in grace and mercy He spared Lot, his wife, and two children.
Mercy is not justice, but neither is it injustice, because injustice would violate righteousness, and God always acts according to His holy character, which is total righteousness. Therefore mercy, which manifests kindness and grace, does no violence to righteousness, and we may see non-justice in God—which is mercy—but we never see injustice in God.
John W. Ritenbaugh
Justice and Grace