The Gemora says that when Rabban Gamliel blinded the eye of Tavi his slave, he was “very happy.” Rashi explains that he was happy because he really wanted to emancipate him, but was unable to do so since freeing a Canaanite slave is a violation of a prohibition, but since he blinded him, he would be free.
[The Ya’avetz raises a technical problem: Rabban Gamliel certainly didn’t blind him intentionally since that would be forbidden, rather it was done accidentally (a proof to this is that he didn’t do it until now), but the Gemora says on 26b that a slave would only go free if he “intended to destroy him.”]
It seems that Rashi would disagree with the Ran (Gittin 20b b’dafei ha’rif) who says that freeing a slave follows the same rules as “lo sei’chanem,” that it is only prohibited if done for the purpose of the slave, but not if done for the need of the master. Based on the Ra”n, it should have been permitted for Rabban Gamliel to free his slave since it brings joy to himself and is not for the benefit of the slave. Can we deduce from this Rashi that he disagrees with the Ra”n and maintains that it is forbidden to emancipate a slave even for the benefit of the master?
It seems that Rashi here is not necessarily against the Ra”n (meaning that even the Ran would hold that Rabban Gamliel wouldn’t be allowed to free his slave for the purpose of giving him joy). The joy that Rabban Gamliel had was not a selfish joy; rather it is because he loved Tavi so much that he wanted to set him free for his own sake. Even the Ra”n would agree that if the only benefit to the master is that he is happy to provide benefit to the slave, that would not qualify as a selfish benefit to permit the freeing of a slave.