And know that the Rambam did not distinguish regarding the prohibition of benefiting from a corpse between an Israelite corpse and an Egyptian. The Tur also did not mention this at all. Our teacher, the Beit Yosef, wrote in section 1 (Shulchan Aruch Yoreh Deah 349:1): A corpse, whether Egyptian or Israelite, and its shrouds—are forbidden for benefit, etc. See there. And so it is in the Responsa of the Rashba (365), and he rejected the one who wished to distinguish between an Israelite and an Egyptian, see there. However, the Tosafot in Bava Kamma (Bava Kamma 10a, at the end of the comments beginning "She-hashor") wrote, and this is their wording: For it was necessary for a slave and an Egyptian owned by an Israelite who fell into a pit, for that one is permitted for benefit. Thus far their words. And it is possible to say regarding their reasoning that since the prohibition of benefit from a corpse is derived from Miriam, from where do we have a source to include an Egyptian? But conversely it is difficult, for from what logic is there to distinguish between this one and that one? Therefore, it is possible that the intent of the Tosafot is also only when he was owned by him, for he is his property, and therefore it is impossible to cause his property to be lost, but not regarding other Egyptians. Nevertheless, there is no correct reasoning in this, for if it is forbidden for benefit, what does it help that he is owned by him? And it is explicitly explained so in the Yerushalmi Shabbat (Chapter 10, Halacha 6) that an Egyptian corpse is permitted for benefit, see there. And there is also a proof from David who betrothed with the foreskins of the Philistines (the Gra). And from the Rambam and the Tur there is no proof, for they are dealing with an Israelite corpse. And the words of our teacher, the Beit Yosef, require further study. (See Mishneh LaMelech at the end of the Laws of Mourning (Rambam Laws of Mourning) who elaborated on this with doubts this way and that way, and afterwards decided from the Yerushalmi for permissibility. And so the Gra ruled.)
ודע דהרמב"ם לא חילק באיסור מת בהנאה, בין מת ישראל ובין מצרי. וגם הטור לא הזכיר זה כלל. ורבינו הבית יוסף כתב בסעיף א (שולחן ערוך יורה דעה שמט, א): מת, בין מצרי בין ישראל, ותכריכיו – אסורים בהנאה וכו' עיין שם. וכן היא בתשובת הרשב"א (שס"ה), ודחה מי שרצה לחלק בין ישראל למצרי, עיין שם. אבל התוספות בבבא קמא (בבא קמא י א, סוף דברי המתחיל "שהשור") כתבו, וזה לשונם: דאצטריך לעבד ולמצרי הקנוי לישראל שנפל לבור, דההוא שרי בהנאה. עד כאן לשונו. ואפשר לומר בטעמם דהא איסור הנאה דמת ילפינן ממרים, ומנא לן לרבות מצרי? אך להיפך קשה, דמאיזה סברא יש לחלק בין זה לזה? ולכן אפשר שגם כוונת התוספות הוא רק כשהיה קנוי לו דממונו הוא, ולכן אי אפשר להפסיד ממונו, אבל לא בשאר מצרי. ומכל מקום אין טעם נכון בזה, דאם הוא אסור בהנאה מה מועיל שקנוי הוא לו? ולהדיא מבואר כן בירושלמי שבת (פרק עשירי הלכה ו) דמת מצרי מותר בהנאה, עיין שם. וגם יש ראיה מדוד שקידש בערלות פלשתים (הגר"א). ומהרמב"ם וטור אין ראיה, דאַמת ישראל קאי. ודברי רבינו הבית יוסף צריכים עיון. (עיין משנה למלך סוף הלכות אבלות (רמב"ם הלכות אבלות) שהאריך בזה בספיקות לכאן ולכאן, ואחר כך הכריע מהירושלמי להיתר. וכן פסק הגר"א.)