Well, if you include "Fantasy", you gotta start with Ancient Greek myths (e.g. Zephyr and Hyakinthos).
If you don't, Wiki lists
True History by the Greek writer Lucian (A.D. 120–185) has been called the earliest surviving example of science fiction and the first ever "gay science fiction story".
- Fredericks, S.C.: “Lucian's True History as SF”, Science Fiction Studies, Vol. 3, No. 1 (March 1976), pp. 49–60
- Gunn, James E. denotes True History as "Proto-Science Fiction", p.249
- Lynne Yamaguchi Fletcher The First Gay Pope and other records, p. 95, Alyson Publications: 1992 ISBN 978-1555832063
For later "real SF", Wiki lists:
An Anglo-American Alliance, a 1906 novel by Gregory Casparian, was the first SF-themed novel to openly portray a lesbian romantic relationship.