"And he said, 'Cursed be Canaan'" (Genesis 9:25). According to the opinion of the one who says that he [Noah] was injured in his own body: Noah was destined to raise up a fourth son who would serve him, and this one [Ham] prevented that from him, because he castrated him. Therefore he cursed his [Ham's] fourth son. And why did he not curse Ham, who did the evil? Because the Holy One, blessed be He, had blessed him, as it is said, "And God blessed Noah and his sons" (Genesis 9:1).
Why Noah Cursed Canaan and Not Ham After the Castration
Midrash Aggadah, Genesis 9:25
ויאמר ארור כנען. לדעת האומר שהוא קבל בעצמו, נח היה לו להעמיד בן רביעי שישמנו וזה מנעו ממנו לפי שסירסו, לפיכך קלל בנו הרביעי, ולמה לא קלל לחם שהוא עשה הרעה, לפי שברכו הקב"ה, שנאמר ויברך אלהים את נח ואת בניו (בראשית ט א):