"And Noah awoke from his wine" (Genesis 9:24). His wine left him, "and he knew what his youngest son had done to him," his unfit son, as you say, "for the bronze altar that was before the LORD was too small to hold" (1 Kings 8:64). "And he said, Cursed be Canaan" (Genesis 9:25). Ham sinned, yet Canaan was cursed. Rabbi Yehuda says: because it is written, "And God blessed Noah and his sons" (Genesis 9:1), and there is no curse where there is a blessing; therefore he said, "Cursed be Canaan." Happy are the righteous: not only do they earn merit for themselves, but they bring merit to their children and their children's children to the end of all generations. Aaron had many sons who deserved to be burned like Nadab and Abihu, as it is said, "those who remained" (Leviticus 10:12), yet the merit of their ancestors protected them. Woe to the wicked: they bring guilt upon themselves and upon their children and their children's children to the end of all generations. Canaan had many sons who deserved to be ordained as scholars, like Tavi the servant of Rabban Gamliel, yet the guilt of their ancestors caused their downfall.
Ham Sinned Yet Canaan Was Cursed
Yalkut Shimoni on Torah 61:11
(בראשית ט כד) וַיִּיקֶץ נֹחַ מִיֵּינוֹ. פֵּרְקוֹ יֵינוֹ וַיֵּדַע אֵת אֲשֶׁר עָשָׂה לוֹ בְּנוֹ הַקָּטָן, בְּנוֹ הַפָּסוּל כְּמָה דְּאַתְּ אָמַר (מלכים א' ח, סד) "כִּי מִזְבַּח הַנְּחשֶׁת אֲשֶׁר לִפְנֵי ה' קָטֹן מֵהָכִיל". (בראשית ט כה) וַיֹּאמֶר אָרוּר כְּנָעַן. חָם חָטָא וּכְנַעַן נִתְקַלֵּל רַבִּי יְהוּדָה אוֹמֵר, לְפִי שֶׁכָּתוּב (בראשית ט, א) "וַיְבָרֶךְ אֱלֹהִים אֶת נֹחַ וְאֶת בָּנָיו", וְאֵין קְלָלָה הֹוָה בִּמְקוֹם בְּרָכָה, לְפִיכָךְ וַיֹּאמֶר אָרוּר כְּנָעַן. אַשְׁרֵיהֶם הַצַּדִּיקִים לֹא דַּיַּין שֶׁזּוֹכִין לְעַצְמָן אֶלָּא שֶׁמְּזַכִּין לִבְנֵיהֶם וְלִבְנֵי בְנֵיהֶם עַד סוֹף כָּל הַדּוֹרוֹת, הַרְבֵּה בָּנִים הָיוּ לוֹ לְאַהֲרֹן שֶׁרְאוּיִן לִישָּׂרֵף כְּנָדָב וַאֲבִיהוּא שֶׁנֶּאֱמַר (ויקרא י, יב) "הַנּוֹתָרִים", אֶלָּא שֶׁזְּכוּת אֲבִיהֶם גָּרְמָה לָהֶם, אוֹי לָהֶם לָרְשָׁעִים שֶׁמְחַיְיבִין לְעַצְמָן וְלִבְנֵיהֶם וְלִבְנֵי בְנֵיהֶם עַד סוֹף עַל הַדּוֹרוֹת, הַרְבֵּה בָּנִים הָיוּ לוֹ לִכְנַעַן שֶׁרְאוּיִן לִסְמֹךְ כְּטָבִי עַבְדּוֹ שֶׁל רַבָּן גַּמְלִיאֵל, אֶלָּא שֶׁחוֹבַת אֲבִיהֶן גָּרְמָה לָהֶם.