This is not an easy one to answer though in short, yes, sex and gender were viewed differently pre-modernity - for lack of a better term - than it is today. Also, it is not as though the sources are super scarce ( /u/sowser and /u/sunagainstgold ?)
I can only speak to a Western context but when we consider how past societies have viewed issues of sex, gender, relationships etc., we always must take into account that e.g. Ancient Greece did not view sexuality along an axis of who you had sex with but rather which role you took during the sexual act. This activity/passivity angle rather than the hetero/homo angle presents a considerable difference to our understanding today.
Similarly, if we follow the theories by Foucault (and not all historians would do that) then the strict concepts of hetero- and homosexuality are essentially a development of bourgeois society. Foucault posits that within the development of modern Western society the shift from - to put it in a simplified form - a world framed by a theological deity to a world framed by science necessitated a shift in discourse. Like Adorno and Horkheimer who locate the development of racial theories within this ontological and epistemological shift, Foucault writes that with the discourse of modernity sexuality becomes an ontological category and thereby a marker for identity.
To simplify it a bit: Because of how modernity changed the perception of the world, it suddenly became necessary to find new explanations for things that previously had been explained with suddenly outdated factors (e.g. God) or didn't require an explanation. This was especially pertinent for the differences between people in general and lead to the development of such categories as race but also our modern categorization of sexuality as divided between hetero- and homosexuals. Homosexuality (and in turn heterosexuality) was not discovered but produced through discourse. As he writes in The History of Sexuality, Vol. 1, p. 43: “Homosexuality appeared as one of the forms of sexuality when it was transposed from the practice of sodomy onto a kind of interior androgyny, a hermaphrodism of the soul. The sodomite had been a temporary aberration; the homosexual was now a species”
And although homosexual practices had been known and practiced throughout history, virtually everywhere, it was this discursive shift, this new ontological category that encouraged people to identify themselves or to view others as homosexual.
One step further, from this, the close development of the Bourgeoisie and Capitalism and the latter's concern with productivity also in the realm of reproduction can help explain the classification of homosexuality as a pathology that had to be suppressed or regulated, as well as the general demonization of sexualities that were not deemed to be “productive.”
This is important because in regard to historical inquiry, it helps us understand and read sources better. We need to find a way to understand the notion of sexuality of the historical actor rather than out own. When we read e.g. medieval sources, we need to keep in mind that sex, including sex between people of the same sex/gender, is discussed differently than we would discuss it today. So when we set out to discover LGBT sources in history, we need to familiarize ourselves with how the society and time period in question writes and discussed sex and then - again, dependent on the time and place in history - sources on this subject might be less rare than we thought.
Edit:
Sources:
Foucault, Michel. The History of Sexuality – Volume I: An Introduction. Trans. Robert Hurley. New York: Vintage Books, 1990.
Foucault, Michel. The History of Sexuality – Volume II: The Use of Pleasure. Trans. Robert Hurley. New York: Vintage Books, 1990.
Rousseau, George and Roy Porter. Sexual Underworlds of the Enlightenment, 1987.
Thomas K. Hubbard, Review of David M. Halperin, How to Do the History of Homosexuality. in Bryn Mawr Classical Review.