"They shall not dwell in your land" (Exodus 23:33). One might think Scripture speaks of a gentile who has accepted upon himself not to worship idols. Therefore the verse teaches, "You shall not hand over a slave" etc. (Deuteronomy 23:16). What is his remedy? "He shall dwell with you, in your midst" etc. (Deuteronomy 23:17). This was difficult for Rabbi Yoshiyah: this phrase "from his master" (Deuteronomy 23:16) should have said "from his god." Rather, Rabbi Yoshiyah said: it speaks of one who sells his slave outside the land. This was difficult for Rabbi Aha bar Yoshiyah: this phrase "who escapes to you" should have said "who escapes from you." Rather, Rabbi Yoshiyah said: it speaks of a slave who fled from outside the land to the land. It was taught: "You shall not hand over." Rabbi says: it speaks of one who acquires a slave on condition to set him free. How so? Where he wrote to him, "When I acquire you, behold you are acquired to yourself from now."
The Runaway Slave Who Flees to the Land of Israel
Yalkut Shimoni on Torah 361:1
(שמות כג לג) לֹא יֵשְׁבוּ בְּאַרְצְךָ. יָכוֹל, בְּגוֹי שֶׁקִּבֵּל עָלָיו שֶׁלֹּא לַעֲבֹד אֱלִילִים הַכָּתוּב מְדַבֵּר. תַּלְמוּד לוֹמַר (דברים כג, טז) "לֹא תַסְגִּיר עֶבֶד" וְגוֹ', מַה תַּקָּנָתוֹ, (שם) "עִמְּךָ יֵשֵׁב בְּקְרְבְּךָ" וְגוֹ'. קַשְׁיָא לֵיהּ לְרַבִּי יֹאשִׁיָּה. הַאי (שם) "מֵעִם אֲדֹנָיו", מֵעִם אֱלֹהָיו מִבַּעְיָא לֵיהּ. אֶלָּא אָמַר רַבִּי יֹאשִׁיָּה. בְּמוֹכֵר עַבְדּוֹ בְּחוּצָה לָאָרֶץ. קַשְׁיָא לֵיהּ לְרַבִּי אָחָא בַּר יֹאשִׁיָּה. הַאי "אֲשֶׁר יִנָּצֵל אֵלֶיךָ", "אֲשֶׁר יִנָּצֵל מֵעִמְּךָ" מִבַּעְיָא לֵיהּ. אֶלָּא אֲמַר רַבִּי יֹאשִׁיָּה. בְּעֶבֶד שֶׁבָּרַח מֵחוּצָה לָאָרֶץ לָאָרֶץ. תַּנְיָא. "לֹא תַסְגִּיר". רַבִּי אוֹמֵר. בְּלוֹקֵחַ עֶבֶד עַל מְנַת לְשַׁחְרְרוֹ, הַכָּתוּב מְדַבֵּר. הֵיכֵי דָמֵי. דְּכְתַב לֵיהּ, לִכְשֶׁאֶקָּחֲךָ הֲרֵי עַצְמְךָ קָנוּי לְךָ מֵעַכְשָׁיו.