Why was Cham allowed in the Teivah? Was he not a Rasha? Rashi brings that he had relations in the Teivah which was forbidden, and we see afterwards what he did to Noah.
See this question which brings the Medrash which counts Cham as a good person. Does anyone have a source to suggest perhaps that he went bad afterwards?