For the past 2,000 years scholars have been puzzled by the biblical curse on Ham, Noah's son.
The traditional understanding has been that Ham entered Noah's tent when Noah had passed out drunk just after the great flood ended and "uncovered" Noah's nakedness – variously interpreted to mean that he sodomized his father or that he simply failed to cover up his naked father and show the proper respect.
But the curse is problematic for several reasons, including because it is stated as applying to Ham's son Cana'an – not to Ham:
And Noah began to be a master of the soil, and he planted a vineyard. And he drank of the wine and became drunk, and he uncovered himself within his tent. And Ham, the father of Canaan, saw his father's nakedness, and he told his two brothers outside. And Shem and Japheth took the garment, and they placed [it] on both of their shoulders, and they walked backwards, and they covered their father's nakedness, and their faces were turned backwards, so that they did not see their father's nakedness. And Noah awoke from his wine, and he knew what his small son had done to him. And he said, "Cursed be Canaan; he shall be a slave among slaves to his brethren." And he said, "Blessed be the Lord, the God of Shem, and may Canaan be a slave to them. May God expand Japheth, and may He dwell in the tents of Shem, and may Canaan be a slave to them." Breshit (Genesis) 9:20-27
Many scholars have long believed that parts of that story was lost or excluded. And scholars have known for centuries that there were (and often are) variant versions of the biblical text. What we see in our Tanakhs is basically the final compiled version of rabbinical Judaism. The Jews of Alexandria, Egypt had a different version of the Hebrew Bible which we now call the Septuagint. And the some of the Jewish sects at the time of the Second Temple's destruction appeared to have other versions of some biblical books.
Now scholars have discovered an answer to the problem of the curse of Ham in a fragment of the Dead Sea Scrolls.
The fragment is from cave 4, and it was scanned by Google as part of their ongoing project (done jointly with the Israel Antiquities Authority) to scan the entire 10,000-plus collection of Dead Sea Scrolls and fragments with a special high definition camera that allows scholars to see writing that is too faded for the naked eye to see – some so faded that even normal magnification devices can't detect it.
According to Ha'aretz, here's what happened when Professor Elisha Qimron, Hanan Ariel and Alexey Yuditsky saw the Google version of that fragment:
…The three scholars found the word “El” (God) written in 10 of the lines in a slightly different font than the usual, which is common in ancient writings. The names Noah, Japheth and “tent of Shem” (one of Ham’s brothers) clearly indicated this text had to do with Genesis 9.
The word “El” appears close to the phrase “tent of Shem,” and might indicate that the intent was to “Hashem” as a synonym for God. By comparing this text with another of the Dead Sea Scrolls, the scholars have come up with another interpretation. The scholars believe that the word “tent” can be interpreted as “land,” and that the text may mean that Hashem (God) lives in the “land of Shem.” Thus, Canaan invaded a land that was not his, and that was the reason his descendants were exiled, not because of his father’s sin.
This interpretation is also known from the Apocryphal Book of Jubilees, which survived in the Ethiopian sacred language of Gez and in Greek. There, it also states that Canaan’s sin was in taking the land in a manner different than the way Noah had intended to divide it, ignoring his brothers’ warning not to do so. “Whoever wrote this text knew this interpretation from the Book of Jubilees,” Ariel said. The conclusion is that this alternative tradition to the biblical version was common in the Judean Desert in Second Temple times and later disappeared.…
In other words, the story is really meant to explain how the land meant for Shem's descendants got into the wrong hands, and to provide justification for pushing Cana'an's descendants out.
I would add that putting your hand "under the thigh" of another person and uttering an oath was a way of dealing contracts in parts of the ancient Near East.
We see this later in Genesis:
And Abraham said to his servant, the elder of his house, who ruled over all that was his, "Please place your hand under my thigh. And I will adjure you by the Lord, the God of the heaven and the God of the earth, that you will not take a wife for my son from the daughters of the Canaanites, in whose midst I dwell. But you shall go to my land and to my birthplace, and you shall take a wife for my son, for Isaac.”…And the servant placed his hand under the thigh of Abraham his master, and he swore to him concerning this matter. Breshit (Genesis) 24:2-4,9
Noah himself can be seen as transgressing an oath he had previously made about the land, and while the two older sons respected the original covenant or contract and did not go back on it, Ham took advantage of his father's drunken stupor to get that land for his son Cana'an and then boasted about it to his brothers.
Later Cana'an is cursed because Cana'an, who would have known that his permission to take the land was gained deceitfully, took it anyway, introducing the concept of an act that is, by the letter of law, permitted, but is morally wrong nonetheless.
That is probably why Cana'an and Ham were not punished immediately for their actions, and why Cana'an's punishment, being made a slave, is a legal action in Torah law. The Torah allows slavery (while closely regulating it and while clearly not liking it). Cana'an's punishment was therefore to be carried out by people who were following the letter of Torah law but not its spirit – just as Cana'an had followed the letter of the law (Noah had, after all, allowed him to conquer the land) but not its spirit.