This isn't really a contradiction. Both ahadith do not negate the fact that manumitting slaves is an encouraged and virtuous deed in Islam. Rather they are about special cases where something else takes precedence over this deed.
The first hadith is about Tadbir, where a person declares that his slave would be free after his (owner's) death This is meant to be an easier means to achieve freedom of slaves since it would be more agreeable to the owners.
The problem in the given incident was that the owner had become bankrupt and according to some narrations also owed a debt:
أن رجلا أعتق غلاما له عن دبر، فاحتاج
A man decided that a slave of his would be manumitted after his death and later on he was in need of money
لم يكن له مال غيره
he had no other property than that slave
عتق رجل من الأنصار غلاما له عن دبر، وكان محتاجا، وكان عليه دين
A man among the Ansar stated that his slave was to be set free after he died; while he was in need, and he owed a debt
Such a person would naturally sell his possessions to meet his daily needs, however the sahabi was hesitant to sell the slave because of the rule (or presumption based on the madhab) that such a slave can not be sold, gifted, pawned or transferred in any way that would interfere with the promised freedom. So the Prophet ﷺ demonstrated that such a pledge can be revoked when there is a need.
Another point of view is that the pledge was not valid in the first place since one can not will the donation to charity of what is greater than a third of their wealth, since that infringes upon the rights of their heirs.
While still another point of view is that the Prophet did not sell the slave, rather gave him for employment for a period of time and that does not conflict with the slave's eventual freedom:
لا بأس ببيع خدمة المدبر إذا احتاج
There is nothing wrong with selling the service of a mudabbar slave when there is need
— Sunan Daraqutni
In either case, the Prophet's action was not discouraging or prohibiting manumission of slaves, rather it was for a special circumstance.
The second hadith affirms that freeing slaves carries reward but implies that the reward for صلة الرحم (good treatment towards kin) is greater. This is applicable in the special case when all three of the following conditions apply:
- One has the ability to free a slave and
- Also has a relative who is really needy and
- He does not have the financial ability to both free the slave and help the relative
In this case the right of the relative takes precedence over that of an unrelated slave. Helping the relative will fetch greater reward than helping the slave. This is inline with the principle that relatives are to be given precedence in charitable deeds. The purpose is not to undercut the importance of manumission of slaves, but rather to elevate the importance of helping relatives.
عن ميمونة، زوج النبي صلى الله عليه وسلم قالت: كانت لي جارية فأعتقتها، فدخل علي النبي صلى الله عليه وسلم، فأخبرته، فقال: آجرك الله، أما إنك لو كنت أعطيتها أخوالك كان أعظم لأجرك
Maimunah, wife of the Probhet (ﷺ) said : I had a slave girl and I set her free. When the Prophet (ﷺ) entered upon me, I informed him (of this). He said :
May Allah give reward for it; if you had given her to your maternal uncles, it would have increased your reward
— Abi Dawud>
Refer to Ibn Hajar's commentary on the hadith.
Note that liberating slaves is an approved act in Islam and among the deeds with highest virtue. That is agreed upon and proven through clear texts:
وما أدراك ما العقبة - فك رقبة - أو إطعام في يوم ذي مسغبة يتيما ذا مقربة
And what can make you know what is [breaking through] the difficult pass?
It is the freeing of a slave
Or feeding on a day of severe hunger an orphan of near relationship
— Quran 90:13-15
Also Allah has made freeing slaves a means of forgiveness from enormities such as murder (4:92), breaking a fast, breaking an oath (5:89 , 58:3) etc. If manumission was a discouraged or inferior deed then this would not be the case.
So it is not possible for any authentic hadith to dissuade from it in absolute terms, although it may be about an exceptional case like the above.