Muslims could buy/trade slaves that were prisoners of war. But with non-Muslims who may have captured leaves by other means, were they allowed to buy these slaves that were captured as free people but are now slaves.
The only permitted source for slavery in Islam is non-Muslim prisoners of war.
وسبب الملك بالرق : هو الكفر ، ومحاربة الله ورسوله ، فإذا أقدر الله المسلمين المجاهدين الباذلين مهجهم وأموالهم ، وجميع قواهم ، وما أعطاهم الله لتكون كلمة الله هي العليا على الكفار ، جعلهم ملكا لهم بالسبي ; إلا إذا اختار الإمام المن أو الفداء ، لما في ذلك من المصلحة على المسلمين
— NOTE: My own translation, so treat with care:
The reason for ownership is disbelief in Allah (kufr), and fighting against Allah and His Messenger ﷺ. If the Muslim warrirors — who dediate to Allah themselves, their blood, their money, and all their strength, and what Allah gave them to make His word superior — are victorious over the disbelievers, they [prisoners of war] become theirs, unless the Imam elects release for nothing or redemption as the Imam deems best for the interest of the Muslims.
The Prophet ﷺ teaches us that Allah will be the enemy on Judgment Day of anyone who sells a free person as a slave:
عَنْ أَبِي هُرَيْرَةَ ـ رضى الله عنه ـ عَنِ النَّبِيِّ صلى الله عليه وسلم قَالَ: قَالَ اللَّهُ
ثَلاَثَةٌ أَنَا خَصْمُهُمْ يَوْمَ الْقِيَامَةِ، رَجُلٌ أَعْطَى بِي ثُمَّ غَدَرَ، وَرَجُلٌ بَاعَ حُرًّا فَأَكَلَ ثَمَنَهُ، وَرَجُلٌ اسْتَأْجَرَ أَجِيرًا فَاسْتَوْفَى مِنْهُ، وَلَمْ يُعْطِ أَجْرَهُ
The Prophet ﷺ said: Allah says:
I will be against three persons on the Day of Resurrection: (1) One who makes a covenant in My Name, but he proves treacherous; (2) One who sells a free person [as a slave] and eats the person's price; (3) And one who employs a laborer and gets the full work done by him but does not pay him his wages.
For more information, you may also want to refer to: