בסורא הוות דברתא בשיבבותיה דרב לא הוות דברתא סברו מיניה משום זכותיה דרב דנפיש איתחזי להו בחילמא רב דנפישא זכותיה טובא הא מילתא זוטרא ליה לרב אלא משום ההוא גברא דשייל מרא וזבילא לקבורה
הא זוטר ליה לרב. נס זה קטן הוא לפי גדולת רב:
The Maharsha understands the Gemara to mean that while the zechus of the other person saved them, certainly Rav's zechus would have been doubly effective. But the Maharsha is bothered by the Gemara, because under the circumstances, why wouldn't it have been Rava's zechus? What mistake did the message from Shamayim need to correct? If there's the zechus of a great tzadik and the zechus of a regular tzadik, and a neis happens, isn't it logical that they both contributed, and that, in fact, the smaller zechus was not even necessary? It's as if you protect a city by surrounding it with a wall. Rav's contribution to the wall was ten feet thick, and the other tzadik's one foot thick. True, to stop this danger, you only needed the one foot, but lemaaseh, the wall was built by both of them. So the Maharsha says that it was because when a zechus brings a neis, something is deducted from the Zechus, as Rav Adda bar Ahava had taught on the previous daf (20b) based on Yaakov Avinu's words קטנתי מכל החסדים. In reward for Rav's great zechus, his zechus wasn't used, so that nothing would be deducted from his account.
So according to the Maharsha, of course Rav's zechus would have worked, but it wasn't necessary to tap his zechus in this case, for whatever reason.
But other mefarshim understand the Gemara to be saying that Rav's greater zechus would not have worked. It would not have protected his neighbors. This, of course, is thoroughly counter intuitive. Several mefarshim step up to the plate, and I think that the best way to describe their explanations is "clever" and enjoyable. Whether their answers are a good pshat in the Gemara or in Hashkafa is a different question.
The connection to our parsha is from the Yismach Moshe in Parshas Balak: He brings from the Targum that the passuk הן עם לבדד ישכן ובגוים לא יתחשב means that Klal Yisrael will inherit the world- that it is eternal- and that they will not be destroyed with the wicked nations at the final judgment. Here are the words of the Targum:
הא עמא בלחודיהון עתידין דיחסנון עלמא ובעממיא לא ייתדנון גמיראHe asks, the two seem to be redundant; if it's eternal, then we know they won't be destroyed. He answers that the passuk is teaching the causality- because of the first, therefore the second. In other words, if all the nations of the world were judged together, then Klal Yisrael's zechusim would save everyone, because our zechusim outweigh whatever aveiros they have. But since we're guaranteed eternity, and can't ever be destroyed, we will not be judged together with the others. Only those that might possibly be destroyed will be judged, and we're exempted. So the passuk is saying that davka because we're eternal, we won't be brought up for judgment together with them, and so our zechusim won't mitigate their sins. As a result, they will be destroyed.
He brings a lomdishe tzushtell from the Rashba brought in the Beis Yosef at the end of YD 111. If a basket of teruma fell into one of two baskets of chulin, one containing 100 times as much as the Teruma which is enough to be mevatel and the other has less than 100 times, which is enough for bitul miderabanan but not mid'oraysa, we say שאני אומר- since it would be battel midoraysa either way, and it's a safek derabanan, Chazal give us the right to halachically assume that the teruma fell into the bigger basket and was battel. The Rishonim ask, but who needs שאני אומר? There's a ליטרא קציעות rule by issurim derabanan that allows you to combine the total volume of the two baskets of chulin even though it fell into one, so it's as if it fell into one basket holding 199 measures! The Rashba answers that since the bigger basket would be mevatel the teruma, it can't count together with the other basket. You only can combine them if neither alone would be mevatel, so they're both relevant to the problem. Since if it fell into the larger one the Teruma would be irrelevant, it can't be counted together with the smaller basket. Here too: since Klal Yisrael is not subject to the same potential din, we are not relevant to the judicial issue, and won't be judged all together.
Back to the Gemara in Taanis: Since Rava was a tzadik gamur, the plague was bichlal not relevant to him. Therefore, his zechus could not save anyone. Only a tzadik that's not a tzadik gamur, who Might be threatened by the plague, but would ultimately be saved by his zechus, can save his neighbors. But Rav was so great, that the plague was totally irrelevant to him, so he couldn't save his neighbors. It's like the opposite of grading on a curve.
The Yismach Moshe is hard to find, so here it is inside.
The Sfas Emes offers two answers.
The people in the area did not accord Rav the honor due such a great tzadik and talmid chacham, or perhaps they were lax in heeding his words. As a result, they did not deserve to be saved in his merit- in a sense, they had thrown away the protection of Rav's zechusim through their insufficient kavod.
Answer Two from the Sfas Emes, based on a yesod from the Chidushei HaRim in Vayeira; this answer is also found in the Malbim in Vayeira 18:24 and also in the Anaf Yosef in the Ein Yaakov from Rav Yonasan Eibschutz: AND, our anonymous commenter tells us, the Maharil in Va'eira, presumably regarding Makkas Bechoros, though it ought to be in Bo.
Chazal say (Shabbos 33b) כיון שניתנה רשות למשחית שוב אינו מבחין בין צדיק לרשע. But this does not apply to a Tzadik Gamur, as we see in Gittin perek Cheilek. So, if a tzadik less than gamur is in the neighborhood, and he would be threatened by כיון שניתנה רשות למשחית שוב אינו מבחין בין צדיק לרשע, Hashem holds back the mashchis in order to save the tzadik. But if a tzadik gamur is there, then he is not endangered by כיון שניתנה רשות. So Hashem can send the משחית in to do his work and not have to worry about the tzadik. Here, Hashem kept the משחית out in order to spare the local tzadik. If Rav were the only tzadik there, though, Hashem would have spared Rav even though the others would die. So it was only because of the lesser tzadik that the neighborhood was spared.
This is not too far from the Yismach Moshe's answer, without the tzushtell to the Rashba in Toras HaBayis.
I say with all sincerity עפר אני תחת כפות רגליהם, but לעניות דעתי הקלושה the hashkafa seems twisted. But the lomdus is nice.