It is my understanding that in most cultures of the world concepts such as "gay" and "straight" were uncommon, and sexuality was considered a 'taste' that ranged in a spectrum. Most men mostly liked girls, but would occasionally be attracted to some men (and vice-versa). This view was common in the Roman Empire, the Han dynasty, Persia, Sengoku Japan, etc..
Nowadays, especially in the western world, being gay is usually seen as not only a sexual orientation or behavior but also a fairly 'strict' identity (strict in the sense that most people reject the bisexual label, despite the fact that research suggests that virtually nobody is 100% straight https://www.telegraph.co.uk/women/sex/no-one-100-straight-sooner-men-embrace-better/ ).
So my question would be, when did this change happen and why?
The ancient world didn't really conceive of homosexuality in the same way we do today. By and large they acknowledged and accepted the existence of love and sexual relationships between people of the same sex (generally men; women were second class citizens and their romantic desires were of lesser concern), but marriage was considered an entirely separate thing, and marriage or the attempt to create a household by a same-sex couple would certainly have been considered deviant and probably illegal. Men who preferred homosexual relationships were still expected to marry women and produce children. In Greece there was a longstanding tradition of pederasty in which an adult man would take a younger boy (usually an adolescent or teenager) under his wing to provide for his education, protection, and introduction into adulthood. These were usually sexual relationships as well, and were considered a rite of passage for the younger partner. An important distinguishing factor here is that one of the members of these relationships was always socially inferior to the other.
Love between adult men certainly also existed in Greece, but had a lot more potential to be problematic because the Greeks were greatly concerned with submissive sexuality being debasing (i.e., being a "pitcher" vs. a "catcher"). This concern was not relevant to heterosexual relationships because the woman was always considered to be of socially inferior status to the man and always the sexually submissive partner, but between two men there was the potential for the one partner to have equal or even superior social status but nonetheless act as the submissive partner. Such a relationship would have been heavily stigmatized (though the submissive partner would have been the primary recipient of disapproval). Sexual relationships between men wherein one was very clearly socially superior to the other were not a cause for concern, and would have been accepted without question.
This same dynamic continued in Rome, although they did not practice pederasty in the same systematized way that the Greeks did. During some periods of Roman history there was a great valorization of sexual morality and keeping sex within the bounds of one's marriage (to a woman), but it's unlikely that monogamy was as hegemonic as it is today in Western culture. In ancient Egypt neither marriage nor sexuality were as regulated as in Greece or Rome, and while homosexual relationships almost certainly existed, they were not really discussed in writing and documentation of these relationships is scarce. Egyptians were big subscribers to the idea of ma`at, or maintaining the correct ordering of the world, and marriage to a woman and production of children were a big part of living one's life "correctly". Even if they engaged in alternative activities in their personal lives, they would not have wanted to document this.
However, scholars have suggested that there is one very large potential example showing the existence of homosexual love in Egypt: The Tomb of the Two Brothers. The egyptologists who discovered the tomb were fairly conservative and interpreted the tomb as belonging to two brothers, perhaps twins, who were so inseparable in life that they chose to build a single tomb for the both of them. More recent evaluations of the tomb tend to favor interpreting the relationship between the men as being one of homosexual love. The tomb owners, Khnumhotep and Niankhkhnum were both royal manicurists/hairstylists (insert gay stereotype here), and constructed an unusual double tomb at Saqqara wherein they are depicted together, sometimes embracing in ways that indicate an affection normally reserved for depictions of men and their wives. It is important to note that both of them did have wives and families, and their wives are sometimes even shown in the same tomb scenes where Niankhkhnum and Khnumhotep are embracing, albeit much smaller and off to the sides. The inclusion of these wives have caused some to invalidate the possibility of a homosexual relationship between the two "brothers", but in this context as we see with Greeks and Romans, homosexual love and heterosexual marriage should not necessarily be considered mutually exclusive.