The Messenger of Allah ﷺ ruled regarding a man who had relations with his wife's slave-girl that if he had forced her, she became free and he owed her mistress a slave-girl like her, but if she had consented willingly, she belonged to him and he still owed her mistress a slave-girl like her.
حدثنا أحمد بن صالح حدثنا عبد الرزاق أخبرنا معمر عن قتادة عن الحسن عن قبيصة بن حريث
أن رسول الله ﷺ قضى في رجل وقع على جارية امرأته إن كان استكرهها فهي حرة وعليه لسيدتها مثلها فإن كانت طاوعته فهي له وعليه لسيدتها مثلها
[Hasan] Narrated by Nasai, in the book of Nikah, chapter "Making the Private Parts Lawful", hadith no. 3365, from the hadith of Abdul-Razzaq, with this wording. Hasan explicitly stated that he heard it directly, as reported by Bayhaqi, 8/240.