Sayyiduna Jabir (may Allah be pleased with him) says that a slave came and pledged allegiance to the Prophet (peace and blessings be upon him) for emigration. He (peace and blessings be upon him) did not know that he was a slave. Then his master came to take him. He (peace and blessings be upon him) said: "Sell him to me." So he (peace and blessings be upon him) bought him in exchange for two black slaves. After that, when taking the pledge, he would ask: "Is he not a slave?"
Imam al-Shafi'i (may Allah have mercy on him) says: If accepting Islam had freed him, a free man would not have been bought from him; but (this was) a person who accepted Islam without leaving a land of war.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الجزية / 18844