First, cutting off the righteous and the wicked is not quite as bad as it first sounds - the righteous have an eternal reward and the wicked do not.
Second, the wickedness of some places, Jerusalem in this, had become so exceedingly great, that this was the only option left for divine providence. Note the comments of the Jamieson-Fausset-Brown Bible Commentary:
- righteous … wicked—not contradictory of Eze 18:4, 9 and Ge 18:23. Ezekiel here views the mere outward aspect of the indiscriminate
universality of the national calamity. But really the same captivity
to the "righteous" would prove a blessing as a wholesome discipline,
which to the "wicked" would be an unmitigated punishment. The godly
were sealed with a mark (Eze 9:4), not for outward exemption from the
common calamity, but as marked for the secret interpositions of
Providence, overruling even evil to their good. The godly were by
comparison so few, that not their salvation but the universality of
the judgment is brought into view here.
Ellicott provides more detail:
(3, 4) The righteous and the wicked.—This explains the green tree and
the dry of Ezekiel 20:47; and “all flesh” of Ezekiel 21:4-5,
corresponds to “all faces” of the same. These expressions are meant to
show the universality of the approaching desolation. The actual
separation in God’s sight between the righteous and the wicked has
already been plainly set forth in 9:4-6. But still in this, as in all
national judgments, the innocent must of necessity be involved in the
same temporal sufferings with the guilty. The general terms of this
prophecy are to be limited by what is elsewhere said of the mercy
which shall be shown to a remnant.
Indeed, on this side of history we now know that a remnant of Israel was saved and has survived until the present. Part of that remnant became the Christian church according to Rom 11.