As is clear from the Mishna (2a), even though the commandment of yibum overrides the prohibition of a man marrying his sister-in-law, it would not permit him to marry her if she is an immediate relative who he cannot marry (e.g. his daughter, niece or mother-in-law). In searching for a source for this halakha, the Gemara quotes a baraita that highlights the word aleha – “upon her” – which appears in both the list of forbidden relatives (Vayikra 18:18) and the commandment of yibum (Devarim 25:5). The Torah’s use of the same word in both places is understood to teach that even in the presence of a potential mitzva, the prohibition remains in place.
It is interesting to note that the Rambam suggests an alternative source for this rule. He points to the first pasuk that discusses the mitzva of yibum (Devarim 25:5), which concludes by saying that the surviving brother should take the widow as his wife, thus fulfilling the commandment of yibum. The Rambam understands this to mean that the only time a person can perform yibum is if, theoretically, there was a possibility of his taking her for a wife independently. Therefore, an immediate relative who the yavam could not possibly marry cannot become his wife through yibum.
The commentaries have noted that when the Rambam offers textual sources that differ from those presented by the Gemara, it is not because he disagrees with the Gemara’s source; rather it is because he believes that the alternative pesukim are simpler to understand. The Maharshal discusses this point at some length in his famous work of halakha called Yam shel Shlomo. There, he points out that in this case the Gemara later on in the perek (chapter, see 6a) appears to reject our Gemara’s source with the argument that there is no real need for a source to prove that a yavam cannot marry an immediate relative who is forbidden to him.