Language:
كتاب الشروط
54  
Conditions
(10)
Chapter: The conditions permissible in the case of a slave who has a writing for emancipation
(10)
باب مَا يَجُوزُ مِنْ شُرُوطِ الْمُكَاتَبِ إِذَا رَضِيَ بِالْبَيْعِ عَلَى أَنْ يُعْتَقَ
Sahih al-Bukhari 2726

Narrated Aiman Al-Makki:

When I visited Aisha she said, "Barirah who had a written contract for her emancipation for a certain amount came to me and said, "O mother of the believers! Buy me and manumit me, as my masters will sell me." Aisha agreed to it. Barirah said, 'My masters will sell me on the condition that my Wala will go to them." Aisha said to her, 'Then I am not in need of you.' The Prophet (ﷺ) heard of that or was told about it and so he asked Aisha, 'What is the problem of Barirah?' He said, 'Buy her and manumit her, no matter what they stipulate.' Aisha added, 'I bought and manumitted her, though her masters had stipulated that her Wala would be for them.' The Prophet (ﷺ) said, The Wala is for the liberator, even if the other stipulated a hundred conditions."

حَدَّثَنَا خَلاَّدُ بْنُ يَحْيَى، حَدَّثَنَا عَبْدُ الْوَاحِدِ بْنُ أَيْمَنَ الْمَكِّيُّ، عَنْ أَبِيهِ، قَالَ دَخَلْتُ عَلَى عَائِشَةَ ـ رضى الله عنها ـ قَالَتْ دَخَلَتْ عَلَىَّ بَرِيرَةُ وَهْىَ مُكَاتَبَةٌ، فَقَالَتْ يَا أُمَّ الْمُؤْمِنِينَ اشْتَرِينِي فَإِنَّ أَهْلِي يَبِيعُونِي فَأَعْتِقِينِي قَالَتْ نَعَمْ‏.‏ قَالَتْ إِنَّ أَهْلِي لاَ يَبِيعُونِي حَتَّى يَشْتَرِطُوا وَلاَئِي‏.‏ قَالَتْ لاَ حَاجَةَ لِي فِيكِ‏.‏ فَسَمِعَ ذَلِكَ النَّبِيُّ صلى الله عليه وسلم أَوْ بَلَغَهُ، فَقَالَ ‏"‏ مَا شَأْنُ بَرِيرَةَ فَقَالَ اشْتَرِيهَا فَأَعْتِقِيهَا وَلْيَشْتَرِطُوا مَا شَاءُوا ‏"‏‏.‏ قَالَتْ فَاشْتَرَيْتُهَا فَأَعْتَقْتُهَا، وَاشْتَرَطَ أَهْلُهَا وَلاَءَهَا، فَقَالَ النَّبِيُّ صلى الله عليه وسلم ‏"‏ الْوَلاَءُ لِمَنْ أَعْتَقَ، وَإِنِ اشْتَرَطُوا مِائَةَ شَرْطٍ ‏"‏‏.‏
Reference : Sahih al-Bukhari 2726
In-book reference : Book 54, Hadith 14
USC-MSA web (English) reference : Vol. 3, Book 50, Hadith 886
  (deprecated numbering scheme)