here is interesting history about same-sex in Muslim society by Jonathan Brown

Jonathan Brown on homosexuality in muslim society

Brown made an article how previous some Muslim & sharai were tolerance of same-sex affection and even the act too tho most agree it was prohibit the punishment was mercif nor their was ijma:

"A wealth of top quality scholarship has demonstrated that Islam, Muslim societies and the Shariah tradition did not conceive of ‘homosexuality’ as an identity. But they did acknowledge that same-sex attraction occurred, often for ‘natural’ reasons (e.g. it was considered normal for men to be attracted to beardless youths, who shared feminine beauty). It is only specific actions, such as sodomy (in Arabic, Liwat)\1]), that show up on the Shariah radar as sins or punishable offenses. It is not same-sex attraction or desires that the Shariah prohibits. It is acting on them...

How Was Homosexuality Dealt with in Pre-Modern Islamic Civilization?

The short answer is that it wasn’t. Like a DEA agent watching a Keith Richards interview, 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 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?  This dissonance only existed for the Hudud crimes, those ‘Limits of God’ whose punishments had been laid out clearly by the Quran and the Prophet’s precedent (adultery/fornication, sexual slander, certain kinds of theft, intoxication, apostasy from Islam and banditry/violent robbery). Though some of these crimes were grave threats to public order (e.g. banditry, theft), and others included violations of the rights of other members of society (e.g. slander), what unified the Hudud crimes was that they were also seen as transgressing the ‘rights of God.’  They were particularly offensive to Him. But because God is most merciful, the Quran and the Prophet’s teachings made it almost impossible to actually punish someone for one of the Hudud crimes. The Quran ordains that the punishment for fornication is 100 lashes, but it also requires four witnesses who saw penetration occur to prove it (the Quran adds that, if someone makes this accusation without four witnesses, s/he is punished with 80 lashes for slander) (Quran 24:2-4). Furthermore, in a commandment that has been central to the application of justice in Islamic history, the Prophet ordered judges to “Ward off the Hudud from the Muslims as much as you can, and if there is a way out for [the accused] then let him go. For it is better for the authority to err in mercy than to err in punishment.” Muslim jurists encapsulated this rule in their maxim ‘Ward off the Hudud by ambiguities (shubuhat),’ compiling vast lists of all the procedural technicalities by which Hudud punishments could be set aside. For example, if a thief stole an item below a certain value, or from an unsecured location, or if the thief simply denied he’d stolen it, he could not be punished with the Hudud punishment of having his hand chopped off (see the appendix for a list of the ones for theft). That does not mean that the thief would escape punishment. His crime would simply drop from the Hudud-level theft (sariqa) to a lower level of theft, which was punishable by a duty of restitution and perhaps a punishment like a year in prison. Since the majority of Sunni schools of law considered Liwat to be an extension of the Hudud crime of Zina, the same procedural safeguards applied. If there was any ambiguity, the Hudud punishment would not be applied. As with the Hanafi school’s ruling on Liwat, dropping the Hudud punishment didn't mean that the guilty party was not punished. But the punishment would be much less severe.

Beyond the general caution with which Hudud crimes were punished, there was also a widespread cultural acceptance of same-sex attraction in Muslim societies. Muslim scholars and judges agreed that Liwat was a grievous sin, but it was too widespread not to treat it with humor. And appreciating male beauty was not unknown to them. A thirteenth-century scholar visiting Cairo from Bukhara would play on his own name and the famously strict criteria that the great Hadith scholar al-Bukhari had for evaluating the soundness of Hadith. When this scholar saw a handsome boy he would say, ‘This is sound according to the criteria of al-Bukhari!”\14]) An influential ninth-century Sunni scholar and chief judge of Baghdad was well known for delighting in encountering handsome young men – and writing poetry about it - to the extent that a critic devoted a whole poem to “a judge who would apply the Hudud punishment for adultery but who sees nothing wrong with Liwat.”  But all of this was just fodder for the judge’s banter with the caliph during their meetings. "

source: The Shariah, Homosexuality & Safeguarding Each Other’s Rights in a Pluralist Society

Another one by him https://www.facebook.com/jonathanacbrown/posts/10154337569469850: " For those of you asking "How could a Muslim scholar support gay marriage?" The answer is easy. I don't support "gay marriage," I support the right of people living in a civil society to engage in contracts that the majority considers backward or immoral....the shariah allows Christians living under Muslim rule to buy, sell and consume wine; Jews to charge interest, and Zoroastrians to have brother-sister (khwotadeh) marriages. This is because Muslims recognized a plurality of laws (shara'i'). "