It was not true that Hashem punished the wicked and the righteous together. In the time of Noach, only Noach and his family were tzadikim (and were less than the ten Avraham was asking for). Thus, everyone who died in the mabul deserved it.
The punishment of the dor haflaga was actually a salvation of the world as the dispersion caused the wicked to lose power and allowed everyone the freedom to establish their own societies. Thus, it actually saved the world from having to be destroyed.
Rashi is saying that the people who do not understand will think that Hashem performs communal punishment with the righteous and the wicked punished together. As a result, they will think that it is not worth being righteous since they will be punished anyways.
Avraham was attempting to save the cities so that those who were potentially righteous could have a chance to do teshuvah. Even the reshaim could do teshuvah if they are frightened enough.
Your comment brings up Avimelech in Perek 20 Pasuk 4 of Vayeirah
ד: וַאֲבִימֶלֶךְ לֹא קָרַב אֵלֶיהָ וַיֹּאמַר אֲדֹנָי הֲגוֹי גַּם
צַדִּיק תַּהֲרֹג
- And Abimelech had not come near to her, and he said, "O Lord, will You kill even a
righteous nation?
ה: הֲלֹא הוּא אָמַר לִי אֲחֹתִי הִוא וְהִיא גַם הִוא אָמְרָה אָחִי
הוּא בְּתָם לְבָבִי וּבְנִקְיֹן כַּפַּי עָשִׂיתִי זֹאת
- Did he not say to me, 'She is my sister'? And she, even she said, 'He is my brother.'
With the innocence of my heart and with the purity
of my hands have I done this."
ו: וַיֹּאמֶר אֵלָיו הָאֱלֹהִים בַּחֲלֹם גַּם אָנֹכִי יָדַעְתִּי כִּי
בְתָם לְבָבְךָ עָשִׂיתָ זֹּאת וָאֶחְשׂךְ גַּם אָנֹכִי אוֹתְךָ מֵחֲטוֹ
לִי עַל כֵּן לֹא נְתַתִּיךָ לִנְגֹּעַ אֵלֶיהָ
- And God said to him in a dream, "I too know that you did this with the innocence of
your heart, and I too have withheld you from sinning
to Me; therefore, I did not let you touch her
Note that Hashem doen't dignify Pasuk 4 with an answer. The claim is actually so ludicrous that Hashem does not even need to say that it is not true. We can see this because Avimelech has to issue a decree telling everyone to leave Avraham and Sarah alone. At least they were better than the Egyptians because Par'o could not trust his people to obey such a command. Thus, even Avimelech realized that this was not a valid argument. Also, Hashem did not threaten to kill everyone, this was Avimelech stating that if he were killed (as the king) the entire nation would be destroyed. Thus, even if the people were completely righteous, Hashem had not threatened anyone other than Avimelech.
Avimelech says (according to Rav Hirsch's translation) "In the innocence of my heart and the integrity of my hands have I done this" Hashem answers "in the innocence of thy heart" but not "integrity of thy hands" which means, yes he thought she was not married, be he still sinned by kidnapping her.