Organ Donation in Halacha
(כג) לֹא־תָלִ֨ין נִבְלָת֜וֹ עַל־הָעֵ֗ץ כִּֽי־קָב֤וֹר תִּקְבְּרֶ֙נּוּ֙ בַּיּ֣וֹם הַה֔וּא כִּֽי־קִלְלַ֥ת אֱלֹהִ֖ים תָּל֑וּי וְלֹ֤א תְטַמֵּא֙ אֶת־אַדְמָ֣תְךָ֔ אֲשֶׁר֙ יְהוָ֣ה אֱלֹהֶ֔יךָ נֹתֵ֥ן לְךָ֖ נַחֲלָֽה׃ (ס)
(23) you must not let his corpse remain on the stake overnight, but must bury him the same day. For an impaled body is an affront to God: you shall not defile the land that the LORD your God is giving you to possess.
תנו רבנן עד היכן הוא בודק עד חוטמו ויש אומרים עד לבו בדק ומצא עליונים מתים לא יאמר כבר מתו התחתונים מעשה היה ומצאו עליונים מתים ותחתונים חיים
The Rabbis taught: If a person is buried under a collapsed building, until what point does one check to clarify whether the victim is still alive? Until what point is he allowed to continue clearing the debris? They said: One clears until the victim’s nose. If there is no sign of life, i.e., if he is not breathing, he is certainly dead. And some say: One clears until the victim’s heart to check for a heartbeat. If several people are buried and one checked and found the upper ones under the debris dead, he should not say: The lower ones are likely also already dead, and there is no point in continuing to search. There was an incident where they found the upper ones dead and the lower ones alive.

(יט) בָּדְקוּ עַד חָטְמוֹ וְלֹא מָצְאוּ בּוֹ נְשָׁמָה מַנִּיחִין אוֹתוֹ שָׁם שֶׁכְּבָר מֵת. בָּדְקוּ וּמָצְאוּ עֶלְיוֹנִים מֵתִים לֹא יֹאמְרוּ כְּבָר מֵתוּ תַּחְתּוֹנִים אֶלָּא מְפַקְּחִין עַל הַכּל שֶׁאֶפְשָׁר בְּמַפּלֶת שֶׁיָּמוּת הָעֶלְיוֹן וְיִהְיֶה הַתַּחְתּוֹן חַי:

If [in the process of clearing the debris,] they [reached] his nose and saw that he was not breathing, he should be left there, for he has died already.

...

(ד) אֲפִלּוּ מְצָאוּהוּ מְרֻצָּץ, שֶׁאֵינוֹ יָכוֹל לִחְיוֹת אֶלָּא לְפִי שָׁעָה, מְפַקְּחִין וּבוֹדְקִים עַד חוֹטְמוֹ; אִם לֹא הִרְגִּישׁוּ בְּחוֹטְמוֹ חַיּוּת, אָז וַדַּאי מֵת לָא שְׁנָא פָּגְעוּ בְּרֹאשׁוֹ תְּחִלָּה, לָא שְׁנָא פָּגְעוּ בְּרַגְלָיו תְּחִלָּה.

Even if the victim was found so severely injured that he cannot live for more than a short while, one must probe [the debris) until one reaches his nose. If one cannot detect signs of respiration at the nose, then he is certainly dead whether the head was uncovered first or whether the feet were uncovered first

(ו) אָדָם אֵינוֹ מְטַמֵּא, עַד שֶׁתֵּצֵא נַפְשׁוֹ. וַאֲפִלּוּ מְגֻיָּד, וַאֲפִלּוּ גוֹסֵס. זוֹקֵק לַיִּבּוּם וּפוֹטֵר מִן הַיִּבּוּם, מַאֲכִיל בַּתְּרוּמָה וּפוֹסֵל בַּתְּרוּמָה. וְכֵן בְּהֵמָה וְחַיָּה אֵינָן מְטַמְּאִין, עַד שֶׁתֵּצֵא נַפְשָׁם. הֻתְּזוּ רָאשֵׁיהֶם, אַף עַל פִּי שֶׁמְּפַרְכְּסִים, טְמֵאִים, כְּגוֹן זָנָב שֶׁל לְטָאָה שֶׁהִיא מְפַרְכָּסֶת:

(6) A human does not impurify [others] until his life leaves him. And even someone dismembered or terminally ill, obligates in or exempts from levirate marriage, and qualifies or disqualifies one from eating Terumah [a portion of a crop given to a priest which becomes holy upon separation, and can only be consumed by priests or their household]. And so too domestic or wild animals do not impurify until their lives leave them. If their heads were cut off, even if they are convulsing, they impurify - like the tail of a lizard which convulses [after being cut off].

(ה) מָצָא עֶלְיוֹנִים מֵתִים, לֹא יֹאמַר: כְּבָר מֵתוּ תַּחְתּוֹנִים, אֶלָּא מְפַקֵחַ עֲלֵיהֶם שֶׁמָּא עֲדַיִן הֵם חַיִּים.

(5) Even if they found him [in exremis], that he can only live for a short hwile, they remove the collapse and check until his nose, and if they do not sense at his nose life then he is definitely dead - it does not matter whether they reached his head or his feet first.

עד היכן הוא בודק - אם דומה למת שאינו מזיז איבריו עד היכן הוא מפקח לדעת האמת:

שו"ת חתם סופר, יו"ד, סי' של"ח

אבל כל שאחר שמוטל כאבן דומם, ואין בו שום דפיקה, ואם אח"כ בטל הנשימה, אין לנו אלא דברי תורתנו הקדושה, שהוא מת, ולא ילינו אותו, והמטמא לו, אם הוא כהן, לוקה אחר ההתראה"

Responsa - Hatam Sofer Yoreh Deah 338

But as long as he lies like an inanimate stone and has no pulse, if afterward breathing ceases, we have only the words of our holy Torah [to rely on and determine] that he is dead, and they shouldn’t leave his body overnight, and one who is defiled by it—if he is a kohein, he is liable for lashes if he is forewarned.

Rav Eliezer Yehuda Waldenberg

Rav Waldenberg dealt with many questions of medicine and Halacha in his comprehensive volumes, titled שו''ת ציץ אליעזר. In a lengthy responsum,he addresses the question of ―brain death and organ transplantation. The main sources that lead to this ruling are the שו''ת חת''ס and .שו''ת חכם צבי

First and foremost, based on the words of רש''י, he rules that as long as the heart beats, a person is alive. He explains that the debate in the Talmud is only a matter of whether the failure to detect beating of the heart is sufficient to declare a person dead, but all agree that a beating heart is a sign of life. Accordingly, Rav Waldenberg rejects ―brain death as it is possible for the brain to die before the heart. He is not troubled by the possibility that by following the conclusion of the Talmud to check the nose for respiration a patient whose heart still beats might be declared dead, as prior to the advent of the ventilator the beating of the heart and the cessation of respiration were essentially simultaneous.