It has been amazing to see how many learning, chesed, tzedakah, and tefillah projects have popped up in the last several days for the zechut that the three boys return home safely (such as this one started by a friend of mine, Jacob Bernstein: here). Even without the zechut of the specific mitzvot, the unity of Klal Yisrael itself is no doubt powerful.
It did remind me of an issue that appears in Rishonim and Achronim. The Gemara in several places (Bava Batra 10b, Rosh Hashanah 4a, Pesachim 8a) records that one who gives tzedakah so that his son will live is a tzadik gamur. This seems to contradict the well-known Mishnah in Avot of Antignos Ish Socho (1:3) who says that we should always serve God not for the purpose of reward. Tosfot, based on the continuation of the Gemara, assumes that the difference is whether or not you will regret the mitzvoth if the desired result does not come about. If you will, then the mitzvah is problematic. If you won’t, the mitzvah is fine. He suggests that Jews usually/always (?) do the mitzvoth regardless and non-Jews do in on condition, and thus relegate the statements to each group accordingly. Others simply distinguish between those who will regret the mitzvah and those who won’t (see for example Shut Ginat Veradim 2 Orach Chaim 28). The Beit Shearim (YD 238) specifically writes that Tosafot was just generalizing, but the real principle is that one cannot do mitzvoth for the sake of a certain outcome if he will regret doing the mitzvah if he is not answered. The Radbaz (3:441) argues that only tzedakah can be done for a specific purpose, as God wanted poor people to be helped so he lowers the bar for proper intention. It is for this reason that we are allowed to “test” God when it comes to tzedakah (Taanit 9a). This is accepted by many, such as the Noda BeYehuda in his Drashot, Ahavat Tzion (10, page 16) cited by Yalkut Yosef (OC 60 note 6). See also Minchat Yitzchak (2:84). Some extend this to all mitzvoth bein adam lachaveiro (Shut Emek Halacha 2:21, and see Atvut Diorayta 13 who develops a theory that would support this). Others simply say that Antignos is referencing the highest level – that of a chasid, while the Gemara is outlining a lower but still rarified level (see Parshanei HaMishna to Avot, also Elyah Rabbah 118:2, Shut Kol Eliyahu EH 1:2). Some suggest that in terms of schar, you need purer motives, but the act is still defined as a mitzvah for other purposes, such as shluchei mitzvah eino nizakin (Shut Levush Mordechai OC 2:26).
The Meshiv Davar (2:45) takes the position of Tosafot and turns it into a lechatchila of sorts: Jews will not regret doing the mitzvah even if their requests are not answered. Therefore, it is a great thing to do mitzvoth under these circumstances because it shows that they recognize that the best thing we can do under difficult situations is turn to God:
שו”ת משיב דבר חלק ב סימן מה
ועו”ג קורא תגר, ולפ”ז י”ל דרש”י ותוס’ ס”ל דודאי אם אמר כדי שיחיה בני, ומת הבן א”צ ליתן, ולא מיקרי בזה עובד ע”מ לקבל פרס, אלא ישראל אינו חוזר על נדרו, מה שאמר סלע זו לצדקה בשביל שיחיה בני, דאע”ג שאינו צריך ליתן עוד, מ”מ מבין שראוי לעשות כן ולנדור בעת צרה אולי יחון ה’ וישמע תפלתו ואם לא נשמע תפלתו עונו גורם לו, משא”כ עו”ג קורא תגר, וא”כ חוזר על שנדר כלל,
This answer resonates with me. When we are faced with a difficult situation, we daven and do mitzvoth, emphasize achdut, and recognize that in the end we need God’s help. Hopefully he will see this as an act of collective teshuvah and will answer our tefillot quickly.