The Satmar Rav in Divrei Yoel (Parshas Vayigash, p. 480; left column) explains how Yaakov Avinu and his family were, halachically, able to leave Eretz Yisroel and settle in Mitzrayim although it is forbidden to settle in a country run by idol worshipers and heretics. The Satmar Rav says:
As for someone leaving the Land of Israel to go to outside lands, it is considered as if they are serving foreign gods. However, this is not the case when holiness is present in the foreign rule, as was the case during Joseph's time in Egypt. On the contrary, during the time of the Canaanites, they served foreign rulers. At that time, Yosef was placed over Egypt, and his rule was sanctified. The verse states, 'G-d has made me a ruler of all Egypt.' Thus, the rule in Egypt was considered holy, according to the promise given: 'Do not be afraid to go down to Egypt, for there I will make you a great nation.'
He then says:
In this context, the greatness of the nation is attributed to their merit in studying the Torah, as stated: 'Who is like the great nation?' Israel is called a great nation because they upheld the Torah and its commandments. As our sages said, in Egypt, Israel continued to study Torah, and even Yehudah was engaged in Torah study. It is also mentioned that a Yeshiva (a place of Torah study) was established in Egypt, and Amram, the elder, sat there.
We know from Rashi (Bereishis 46:28) that the words "להורת לפניו – Lehoros Lefanav" mean:
לפניו BEFORE HIM — means before he should arrive there. A Midrashic comment is: להורת לפניו (in the sense of, “that there might be teaching before him”) — to establish for him a House of Study from which Teaching (הוראה or תורה) might go forth (Genesis Rabbah 95:3).
But.... The navi Yechezkel (20:8, see Rashi there) says:
But they rebelled against me, and would not hearken to me: they did not cast away every man the abominations of their eyes, neither did they forsake the idols of Miżrayim: then I said, I will pour out my fury upon them, to accomplish my anger against them in the midst of the land of Miżrayim.
But they rebelled against Me They are the wicked, the majority of Israel, who died in the three days of darkness, as it is said (Exod. 13:18): “and the children of Israel went out of Egypt, (חֲמֻשִּׁים)”one out of fifty, and some say, one out of five hundred. (Rashi)
The Satmar Rav says that even in Mitzrayim, the Jewish people continued to study Torah. How to reconcile this with what the Navi Yechezkel says? Are there clear sources that say that Yisroel was studying Torah in Egypt? And if so, how to reconcile that with the teachings that B'nei Yisroel were sunken to the -49th level of impurity?
We know from different source (Daas Zkenim) that since the Torah did not cease from shevet Levi, they were not enslaved (שלא פסקה מהם תורה כלל ולפיכך לא נשתעבדו במצרים), but this applies only to Shevet Levi.