For centuries [male homosexuality] was widely practiced, mainly by the literati and ruling classes, though there is plenty of evidence of same-sex love between ordinary Chinese, even in the countryside. As long as these men married and had children, it was acceptable for them to carry on affairs with men outside the home. Many emperors kept male lovers along with their harems of concubines. Han Dynasty scribes actually catalogued the emperors’ male lovers. Homosexuality was not an identity, it was something men simply did for entertainment, and often to display their class privilege.
This all changed when Mao took over in 1949, after which "homosexuality was labeled both a psychological disorder and an act of hooliganism." Previous Dish coverage of China's homosexual taboo here and here.