The short answer is that it wasn’t.
The guardians of the Shariah (judges, concerned scholars, market police, etc.) turned a blind eye to the private lives of the populace. Thus, despite the endless production of poetry extolling the beauty of young boys, instances of people being punished for Liwat [sodomy] are exceedingly rare (I have only come across a few examples in Islamic history). Of course, Muslim jurists knew that homosexuality existed all around them. And they disapproved. As Ibn ‘Abd al-Salam wrote, people only seem concerned about sins if they were socially rejected, not if they were objectionable to God. People were mortified by eating in public during Ramadan, he complained, but they saw no problem with ubiquitous sodomy.
Why this dissonance between the rules of the Shariah and their application?
Read the article by Dr Jonathan Brown here