Notice the incident: "So Noah awoke from his wine, and knew what his younger son had done to him" (Genesis 9:24). An illicit sexual act is indicated. While Noah was drunk, he had no idea what was occurring.
The difficulty in this verse is one of grammar. Similar problems exist elsewhere in Scripture. Notice, for instance, Exodus 34:28: "So he [Moses] was there with the LORD forty days and forty nights; he neither ate bread nor drank water. And He wrote on the tablets the words of the covenant, the Ten Commandments." In the Hebrew text, "He wrote" seems to refer to Moses, but Exodus 31:18 and Deuteronomy 9:10 prove that God wrote the Ten Commandments on the stone tables. Thus, modern translations that capitalize pronouns that refer to Deity correctly translate this as "He [the LORD] wrote."
Armed with this example, we can now attempt to solve the problem in Genesis 9 by seeing verse 24 in its context:
Then he [Noah] drank of the wine and was drunk, and became uncovered in his tent. And Ham, the father of Canaan, saw the nakedness of his father, and told his two brothers outside. But Shem and Japheth took a garment, laid it on both their shoulders, and went backward and covered the nakedness of their father. Their faces were turned away, and they did not see their father's nakedness. So Noah awoke from his wine, and knew what his [Ham's] younger son [or, more properly, youngest son] had done to him. Then he said: "Cursed be Canaan . . ." (verses 21-25).
The situation begins with Noah becoming drunk and being violated ("became uncovered"; see Leviticus 18:6-7). The perpetrator, Canaan, is named in verse 22 as Ham's son. That Ham is Canaan's father is emphasized twice in the account (verses 22, 24). The pronoun "his," then, properly refers back to Ham, not to Noah. Ham was the first on the scene after his son's perverse act, guessed what had happened, and reported it to his brothers to seek counsel about what they should do. Later, when Noah awakes, there is no doubt in his mind that Canaan had defiled him, and he curses him for it.
Finally, was Canaan really the youngest son of Ham? Genesis 10:6 indicates he was: "The sons of Ham were Cush, Mizraim, Put, and Canaan." Canaan is listed last in order of birth. Canaan was the youngest son of Ham.
Canaan was not punished for something Ham did. Canaan was punished for his own sin.