Yoreh Deah Siman 267 Seif 10

י בַּמֶּה דְּבָרִים אֲמוּרִים, שֶׁכְּשֶׁלָּקַח עֶבֶד מֵהָעוֹבֵד כּוֹכָבִים אֵין הַגּוּף קָנוּי לוֹ, כְּשֶׁאוֹתוֹ עוֹבֵד כּוֹכָבִים קָנָה אוֹתוֹ עֶבֶד עַל יְדֵי שֶׁנִּמְכַּר לוֹ הוּא עַצְמוֹ. אֲבָל אִם קְנָאוֹ בְּדִינָא דְּמַלְכוּתָא, דְּקָנֵי לֵיהּ גּוּפֵיהּ, וּלְקָחוֹ מִמֶּנּוּ יִשְׂרָאֵל, אִם קָדַם וְטָבַל לְשֵׁם בֶּן חוֹרִין לֹא קָנָה עַצְמוֹ בּוֹ חוֹרִין.

This is what we are saying, that the slave we took from the Idolater we don’t own him (his body), when he (the) idolater purchases him as a slave by means of the slave selling himself. However if he is purchased (by the Idolater) according to the local law, his body belongs to him (his master), and then if he is acquired by a Jew (it belongs to him), and he purchased him (his body) before (immersion) and then he immerses him it will be for his freedom and he would of bought himself a free man.