(Gen. 26:3:) SOJOURN IN THIS LAND. Rabbi Hanan said in the name of Rabbi Samuel bar Rabbi Isaac: Why <was this said>? Because he did not wish to become defiled outside the Land. Since a decree had been decreed, as it is stated (in Gen. 26:1): AND THERE WAS A FAMINE, therefore it says (in Gen. 26:3): SOJOURN IN THIS LAND. Rabbi Joshua ben Levi said: In this world the righteous were torn apart (Heb. metorafin, from the root TRP), as it is stated (in Ps. 111:5): HE HAS GIVEN PREY (teref, from the root TRP) TO THOSE WHO FEAR HIM. But in the world to come (ibid., continuing): HE WILL REMEMBER HIS COVENANT FOREVER.
Why Isaac Was Told to Sojourn in the Land During Famine
Midrash Tanchuma Buber, Toldot 6:2
גור בארץ הזאת (שם ג), אמר ר' חנן בשם ר' שמואל ב"ר יצחק למה אינו רוצה שיטמא בחוץ לארץ, מפני שנגזרה גזירה, שנאמר ויהי רעב, לפיכך הוא אומר גור בארץ הזאת. אמר ר' יהושע בן לוי בעולם הזה צדיקים היו מטורפין, שנאמר טרף נתן ליראיו (תהלים קיא ה), אבל לעולם הבא יזכור לעולם בריתו (שם).