If someone has a sickness that by current medical knowledge is terminal and has no chance of being cured, is it proper to daven for that person to get better? Might this be considered a tefilas shav or davening for a miracle?
To quote the Gemara in Berachos 10a:
For background: King Chizkiya was ill. Yeshaya gave him a Nevuah that he would die from this illness, and after telling Chizkiya that there was nothing that could be done at this point, as the decree had already been handed down, Chizkiya had this to say:
בן אמוץ כלה נבואתך וצא כך מקובלני מבית אבי אבא אפי' חרב חדה מונחת על צוארו של אדם אל ימנע עצמו מן הרחמים
Son of Amotz, cease your prophecy and leave! Thus have I accepted from the house of my forefather: even if a sharp sword is placed on a person’s neck, he should not withhold himself from mercy.
As the verses in Yeshaya 38 continue, Chizkiya davened that he recover, and indeed he did, gaining for himself another 15 years on the throne.
According to Rashi, the tradition to which Chizkiya refers is the fact that, as described at the very end of Sefer Shmuel, his forefather David saw the malach prepared to smite Yerushalayim but still prayed.
What we see from here is that even if all seems lost, the doors of prayer are never closed. One is always able to pray.
In fact, this is actually codified in Halacha. One who is on his deathbed should say Vidui, whose basic text, as recorded by the Shulchan Aruch (YD 338:2), reads as follows:
מוֹדֶה אֲנִי לְפָנֶיךָ ה' אֱלֹהַי וֵאלֹהֵי אֲבוֹתַי שֶׁרְפוּאָתִי וּמִיתָתִי בְּיָדְךָ, יְהִי רָצוֹן מִלְּפָנֶיךָ שֶׁתְּרַפְּאֵנִי רְפוּאָה שְׁלֵמָה, וְאִם אָמוּת, תְּהֵא מִיתָתִי כַּפָּרָה עַל כָּל חֲטָאִים וַעֲוֹנוֹת וּפְשָׁעִים, שֶׁחָטָאתִי וְשֶׁעָוִיתִי וְשֶׁפָּשַׁעְתִּי לְפָנֶיךָ, וְתֵן חֶלְקִי בְּגַן עֵדֶן, וְזַכֵּנִי לָעוֹלָם הַבָּא הַצָּפוֹן לַצַּדִּיקִים.
I admit to You, Hashem, my G-d and the G-d of my forefathers, that my healing and my death are in Your hands. May it be Your will before You that You heal me with a complete healing, but if I die, may my death be an atonement for all of my sins which I have sinned before You, and give my portion in Gan Eden, and may I merit the World to Come which is hidden in waiting for the righteous.
While a large portion of this prayer describes the imminent death which the one praying will seemingly be subjected to, what it is really saying is that Hashem should spare him and let him live, but that if he should die anyway, at least let it be an atonement for his sins. Like by Chizkiya and David, the one praying should never despair, even if there is a sharp sword on his throat.
Perhaps you may argue that the OP’s case is different, though, as it’s someone else davening for him, rather than the patient davening for himself. To that I point to an earlier Gemara in Berachos, on 5b:
אין חבוש מתיר עצמו מבית האסורים
A prisoner cannot free himself from prison.
In context, this means that while a sick person cannot pray to be saved from his own ailment, someone else can. Certainly in our case, where a sick person can save himself, someone else can!
This appears to be addressed by R. Yehuda HaChossid.
Sefer Chassidim # 794
אל יתפלל אדם תפלה שאי אפשר לעשות בקשתו אע"פ שהיכולת ביד הקב"ה אין לבקש דבר שאין נעשה (כפי הטבע) כגון אם אשתו הפילה לשמונה חדשים ברור הוא שאין הולד של קיימא אין מתפללים עליו שיחיה אסור לבקש דבר שאינו ראוי לומר כגון יהי רצון שתלד אשתי לח' חדשים ויחיה הולד ואסור להתפלל שיעשה לו הקב"ה נס בשינוי העולם שאם יש לו אילן שיוציא פירות קודם זמנו כמעשה דר' יוסי בן אבין וכר' יוסי דמן יוקרת בתענית
A man should not pray a prayer that is impossible to be fulfilled. Even though God has the ability to do it, one cannot request something that cannot be done (within nature). For example if his wife discharged the fetus at eight months it is certain that the fetus is not viable [and therefore] we do not pray for it to live. It is forbidden to request something that is not fitting to say, such as "may it be [God's] will that my wife give birth at eight months and the fetus survive". It is forbidden to pray that God perform a miracle that deviates from [the natural order of] the world, [such as] if he has a tree that it should give forth fruit before its time like the incident with R. Yosi Ben Avin and like R. Yosi of Yokeres in [Maseches] Ta'anis.
Praying for a Miracle
Rav Hershel Schachter writes regarding the prohibition of asking G-d for a miracle: "The Shaarei Teshuvah quotes the three exceptions to the rule as stated by the Acharonim, as to when one is permitted to ask for a nes: 1) One may ask for a nes nistar. For this is what hashgacha is all about- God controls the world from behind the scenes, without openly violating any of the rules of nature. 2)Since we believe that, "ein mazal le-yisrael," that the Jewish people are, "lemala min hateva," there is nothing at all improper about requesting a nes nigleh on their behalf. 3) Even if the nes is not for Klal Yisrael, but only on behalf of an unusual tzadik, this too is allowed, as is evidenced from the various stories related in the Gemara Taanit regarding several tzadikim who prayed for miracles. The great tzadik is also "lemala min hateva."
In Parshat Korach we find Moshe Rabbeinu requesting of God that even if the opening of Gehenom not be here, that He make a nes and "yivra Hashem" - let it move to here. Because the miracle was needed- either for klal yisrael or the unusual tzadik- Moshe was allowed to pray for it. A similar situation appears in the Haftorah. Shmuel Ha-navi calls upon God to bring about a miracle on Shmuel's personal behalf, to indicate his righteousness. This appears to be the thematic similarity between the sedra and the Haftorah: the exceptions to the rule i.e. when one is permitted to pray for a miracle.
To illustrate this point, I remember many years ago, when I visited the Ponovez Yeshina in Benai Brak, the tzibbur was reciting tehillim on behalf of a cancer patient on whom the doctors had given up hope. The Mashgiach, Rav Yecheskel Levenstein - refused to participate in the prayers because in effect they were praying for a miracle."
There is much discussion in the medical halacha literature regarding the permissibility of praying for the DEATH of a terminally-ill patient. However, it appears from Rav Shachter's analysis above that the reverse question must also be addressed. Is one allowed to pray for the continued LIFE of a terminal patient? The answer, I suspect, is not absolute. In many cases praying for the cure of a terminal patient may only require a nes nistar, which is permissible. Apparently, Rav Levenstein ZT"L felt that an even more open miracle would have been required in the case of the cancer patient.
There's a different angle to this question:
Practically any Mitzvah has two "applications" - חפצא and גברא, first the object on which the M. is performed and the second is the subject that performs the M.
This is learned from B"B 10a:
" שאל טורנוסרופוס הרשע את ר"ע אם אלהיכם אוהב עניים הוא מפני מה אינו מפרנסם א"ל כדי שניצול אנו בהן מדינה של גיהנם"
"And this is the question that Turnus Rufus the wicked asked Rabbi Akiva: If your God loves the poor, for what reason does He not support them Himself? Rabbi Akiva said to him: He commands us to sustain the poor, so that through them and the charity we give them we will be saved from the judgment of Gehenna."
R"A's answer was that [even in such a clear case of giving out] the giver profits from the good deed.
Same with Teffilah - it helps not only the receiver but the person that davens - it develops good qualities, such as devotion, altruism, caring, belief, togetherness etc. So with no relation to the results for the object of the Teffilah, it surely helps the person - and it is worth doing it!
There are two sorts of "good"s - subjective (what we think is good) and objective (what Hashem knows is good). It is more preferable (let me say it mildly) to daven in general terms, like Moses when he said "א-ל נא רפא נא לה", i.g. asking Hashem to have His mercy and do general good to a person, than asking for something specific, that looks good in our eyes, e.g. asking for a person to complete recovery.
As we don't know the G-d's plan for that patient and what is objectively good for him, we better pray in general terms, as I outlined.
Yet another angle:
As medicine is a science, any recovery is subject to statistical deviation - it always falls between 0% and a 100%, and it is never EITHER. So be it 1 in a billion, there's always a chance.
A miracle, in this case, would be something that contradicts the [G-d's] laws of nature, as the Gemmorah in Berochos says "turning a female fetus into male" or for example pumping milk thru his veins instead of blood.