תני סיעות בני אדם שהיו מהלכין בדרך פגעו להן גוים ואמרו תנו לנו אחד מכם ונהרוג אותו ואם לאו הרי אנו הורגים את כולכם אפי' כולן נהרגים לא ימסרו נפש אחת מישראל ייחדו להן אחד כגון שבע בן בכרי ימסרו אותו ואל ייהרגו א"ר שמעון בן לקיש והוא שיהא חייב מיתה כשבע בן בכרי ורבי יוחנן אמר אע"פ שאינו חייב מיתה כשבע בן בכרי.
It was taught: If a group of people were traveling and they chanced upon a marauding army which demands of them, "Hand over one of your group, or we will kill all of you," you may not hand anyone over, even though all will end up being killed. If however they specify an individual, you may hand him over, as was the case of Sheva the son of Bichri. Rabbi Shimon ben Laskish says that the case of Sheva the son of Bichri was different since he was liable for the the death penalty. Rabbi Yochanan says that even had he not been liable for the death penalty, [he could have been handed over].
שו"ת נודע ביהודה מ"ת יו״ד רי
ונשאלו שם חכמי העיר אם מותר לחתוך בגוף המת במקום הזה כדי לראות במופת שורש המכה הזאת כדי להתלמד מזה בהנהגת הרופאים מכאן ולהבא...
אבל בנדון דידן אין כאן שום חולה הצריך לזה רק שרוצים ללמוד חכמה זו אולי יזדמן חולה שיהיה צריך לזה ודאי דלא דחינן משום חששא קלה זו שום איסור תורה או אפילו איסור דרבנן...
וחלילה להתיר דבר זה ואפילו רופאי האומות אינן עושים נסיון בחכמת הניתוח ע"י שום מת כי אם בהרוגים ע"פ משפט או במי שהסכים בעצמו בחייו לכך ואם אנו ח"ו מקילים בדבר זה א"כ ינתחו כל המתים כדי ללמוד סידור אברים הפנימים ומהותן כדי שידעו לעשות רפואות להחיים.
Responsa Noda Bi-Yehuda YD 210
The scholars of the city were asked if it is permissible to dissect the body of the dead in this place in order to see the source of the wound, in order to derive knowledge for the behavior of doctors from now on...
But in this case, there is no patient who needs this. It is just that we want to acquire this knowledge, in the case that a patient appears before us who needs this. For this purpose we do not push off due to this small likelihood any biblical or rabbinic prohibition.
It is forbidden to permit this matter; even the gentile physicians do not perform experiments with dissection upon any corpse, with the exception of those killed by the law, or with one who agreed to this during his lifetime. If we heaven forbid are lenient in this matter, they will come to dissect all corpses in order to learn the arrangement of the inner limbs and their natures, so that they will know how to cure the living.