Another interpretation: Why did he (Jacob) not seek to be buried in Egypt? So that they would not make him into an object of idolatry; for just as punishment is exacted from the worshipers of idolatry, so too is punishment exacted from the idolatry itself, as it is said (in Exodus 12:12): "And against all the gods of Egypt I will execute judgments; I am the LORD." And so you find with Daniel: once he interpreted the dream for Nebuchadnezzar, what is written? "Then Nebuchadnezzar fell upon his face and paid homage to Daniel, and commanded that they offer to him an offering and incense" (Daniel 2:46). But Daniel did not seek it. He said: Just as punishment is exacted from the worshipers of idolatry, so is punishment exacted from it. And so you find with Hiram: once he made himself a god, what is written of him? "Because your heart is proud, and you have said, 'I am a god'" (Ezekiel 28:2). The Holy One, blessed be He, said to him: "Behold, you are wiser than Daniel" (Ezekiel 28:3). Nebuchadnezzar sought to draw near to him (Daniel), and he refused; yet you have made yourself a god. What is your end? "I have cast you upon the ground" (Ezekiel 28:17), and so forth.
Why Jacob Refused Burial in Egypt and the Idol's Own Punishment
Midrash Tanchuma Buber, Vayechi 5:4
ד"א מפני מה לא בקש ליקבר במצרים, שלא יעשו בו ע"ז שכשם שנפרעין מעובדי ע"ז, כך נפרעין מע"ז עצמה, שנאמר ובכל אלהי מצרים אעשה שפטים אני ה' (שמות יב יב). וכן אתה מוצא בדניאל, כיון שפתר לנבוכדנצר את החלום, מה כתיב באדין נבוכדנצר נפל על אנפוהי ולדניאל סגיד ומנחה וניחוחין אמר לנסכה ליה (דניאל ב מו), אבל דניאל לא בקש אמר כשם שנפרעין מעובדי ע"ז כך נפרעים ממנה. וכן אתה מוצא בחירם, כיון שעשה עצמו אלוה מה כתיב בו, יען (כי) גבה לבך ותאמר אל אני (יחזקאל כח ב), א"ל הקב"ה הנה חכם אתה מדניאל, נבוכדנצר בקש לקרב לו ולא רצה ואת עשה עצמך אלוה, מה סופך (אל) [על] ארץ השלכתיך וגו'.