Ayesha reported,

Aishah, Umm Muiminin, said, "Barirah came to me while she was working under a contract to buy her freedom. She said, 'Umm Muiminin, buy me, for my masters are willing to sell me, and then set me free.'I said, 'Yes.'She said, 'But my masters will not sell me unless they stipulate that my right of inheritance (wala) remains with them.'I said, 'Then I have no need of you.'The Prophet ﷺ heard of this, or it reached him, and he asked, 'What is the matter with Barirah?'He then said, 'Buy her and set her free, and let them stipulate whatever they wish.'"Aishah said, "So I bought her and set her free, and her masters stipulated that the wala would belong to them. The Prophet ﷺ said, 'The wala belongs to the one who sets the slave free, even if they stipulate a hundred conditions.'"

Bukhari 2726

Sahih

حدثنا خلاد بن يحيى حدثنا عبد الواحد بن أيمن المكي عن أبيه قال دخلت على

عائشة رضي الله عنها قالت

دخلت علي بريرة وهي مكاتبة فقالت يا أم المؤمنين اشتريني فإن أهلي يبيعوني فأعتقيني قالت نعم قالت إن أهلي لا يبيعوني حتى يشترطوا ولائي قالت لا حاجة لي فيك فسمع ذلك النبي ﷺ أو بلغه فقال ما شأن بريرة فقال اشتريها فأعتقيها وليشترطوا ما شاءوا قالت فاشتريتها فأعتقتها واشترط أهلها ولاءها فقال النبي ﷺ الولاء لمن أعتق وإن اشترطوا مائة شرط

البخاري 2726صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Conditions
Chapter
What is permissible of conditions for the mukatab if he agrees to the sale on condition of being freed
Numbering
Darussalam 2726
Bukhari 2726