Our Gemara on amud aleph discusses why Avraham was punished with the enslavement of his descendants in Egypt. Three opinions are offered:
אָמַר רַבִּי אֲבָהוּ אָמַר רַבִּי אֶלְעָזָר: מִפְּנֵי מָה נֶעֱנַשׁ אַבְרָהָם אָבִינוּ וְנִשְׁתַּעְבְּדוּ בָּנָיו לְמִצְרַיִם מָאתַיִם וְעֶשֶׂר שָׁנִים — מִפְּנֵי שֶׁעָשָׂה אַנְגַּרְיָיא בְּתַלְמִידֵי חֲכָמִים, שֶׁנֶּאֱמַר: ״וַיָּרֶק אֶת חֲנִיכָיו יְלִידֵי בֵיתוֹ״.
Rabbi Abbahu said that Rabbi Elazar said: For what reason was Abraham our Patriarch punished and his children enslaved to Egypt for 210 years? Because he made a draft [angarya] of Torah scholars, as it is stated: “He led forth his trained men, born in his house” (Genesis 14:14). These trained men that he took to war were actually his disciples, who were Torah scholars.
וּשְׁמוּאֵל אָמַר: מִפְּנֵי שֶׁהִפְרִיז עַל מִדּוֹתָיו שֶׁל הַקָּדוֹשׁ בָּרוּךְ הוּא, שֶׁנֶּאֱמַר: ״בַּמָּה אֵדַע כִּי אִירָשֶׁנָּה״. וְרַבִּי יוֹחָנָן אָמַר: שֶׁהִפְרִישׁ בְּנֵי אָדָם מִלְּהִכָּנֵס תַּחַת כַּנְפֵי הַשְּׁכִינָה, שֶׁנֶּאֱמַר: ״תֶּן לִי הַנֶּפֶשׁ וְהָרְכֻשׁ קַח לָךְ״.
And Shmuel said: Because he greatly examined [hifriz] the characteristics of the Holy One, Blessed be He, as it is stated: “Whereby shall I know that I shall inherit it?” (Genesis 15:8). And Rabbi Yoḥanan said: He was punished because he distanced people from entering under the wings of the Divine Presence, as it is stated that the king of Sodom said to him: “Give me the people and take the goods to yourself” (Genesis 14:21), but Abraham refused to take any goods either. If he had not listened to the king of Sodom and had allowed the people to remain with him, he would have brought the prisoners under the wings of the Divine Presence.
The Maharal (Gevuros Hashem 5:9) sees all three reasons as different ways of expressing an aspect of Avraham’s personality that was missing in small elements, leading to a legacy burden and deficiency in his children, which required the experience of slavery to expunge. The amoraim were not disagreeing, but instead emphasizing different manifestations. He explains the verse itself corresponds to this (Bereishis 15:13):
וַיֹּ֣אמֶר לְאַבְרָ֗ם יָדֹ֨עַ תֵּדַ֜ע כִּי־גֵ֣ר ׀ יִהְיֶ֣ה זַרְעֲךָ֗ בְּאֶ֙רֶץ֙ לֹ֣א לָהֶ֔ם וַעֲבָד֖וּם וְעִנּ֣וּ אֹתָ֑ם אַרְבַּ֥ע מֵא֖וֹת שָׁנָֽה׃
And [God] said to Abram, “Know well that your offspring shall be strangers in a land not theirs, and they shall be enslaved and oppressed four hundred years;
His descendants needed to experience being a stranger to counteract Avraham’s (infinitesimal) disregard for Torah scholars. Torah scholars who are humble and understand that they have much to learn, conduct themselves in this world as if they are strangers.
Being enslaved came from an over-activation of Middas Hadin a certain kind of exactitude. Avraham challenging and asking God for a sign to know for sure if he will inherit the land came from a degree of rigidity and strictness that servitude would counteract. Presumably empathy would be developed from the suffering, perhaps reminiscent of (Shemos 23:9):
וְגֵ֖ר לֹ֣א תִלְחָ֑ץ וְאַתֶּ֗ם יְדַעְתֶּם֙ אֶת־נֶ֣פֶשׁ הַגֵּ֔ר כִּֽי־גֵרִ֥ים הֱיִיתֶ֖ם בְּאֶ֥רֶץ מִצְרָֽיִם׃
You shall not oppress a stranger, for you know the feelings of the stranger, having yourselves been strangers in the land of Egypt.
The oppression came from Avraham not inviting the prisoners to enter under the Divine presence and bring them to Torah. Maharal asserts that Jews suffer under the hand of Gentiles due to the unredeemed holy sparks within the Gentiles that have not been liberated, which gives them power over the Jews. Maharal’s prooftext is (Bamidbar 33:55):
וְאִם־לֹ֨א תוֹרִ֜ישׁוּ אֶת־יֹשְׁבֵ֣י הָאָ֘רֶץ֮ מִפְּנֵיכֶם֒ וְהָיָה֙ אֲשֶׁ֣ר תּוֹתִ֣ירוּ מֵהֶ֔ם לְשִׂכִּים֙ בְּעֵ֣ינֵיכֶ֔ם וְלִצְנִינִ֖ם בְּצִדֵּיכֶ֑ם וְצָרְר֣וּ אֶתְכֶ֔ם עַל־הָאָ֕רֶץ אֲשֶׁ֥ר אַתֶּ֖ם יֹשְׁבִ֥ים בָּֽהּ׃
But if you do not dispossess the inhabitants of the land, those whom you allow to remain shall be stings in your eyes and thorns in your sides, and they shall harass you in the land in which you live;
I would add a prooftext, we also find the Gemara Sanhedrin (99b) which says that Timna wanted to convert but she was not accepted. Still wanting to be attached to this grand family, she ends up as a concubine to Esav, eventually becoming the matriach of Amalek.
In any case, all this is not only true spiritually but also true psychologically. Whatever we do not resolve in ourselves becomes a psychological legacy burden to our children.