In TNG: “The Outcast” Commander Riker falls in love with Soren, a member of the apparently androgynous J'naii species. In this genderless society Soren feels like a woman, something that is not only scorned but downright illegal on the J'naii homeworld. Even worse, anyone infringing the law is subjected to a psychotectic therapy, a form of “re-education”.
Rick Berman tried not to let perceptions of what the public would find acceptable “influence us too much” in the choice of Riker’s opposite, adding “but having Riker engaged in passionate kisses with a male actor might have been a little unpalatable to viewers.” Jonathan Frakes felt otherwise and would later criticize the decision to cast women in the roles of the J'naii, as a love affair apparently shared between two men would have made the statement of the episode stronger.
While the mission to portray a gay relationship in the 24th century has not been achieved, the episode still manages to hit on transgender issues due to the premise of Soren finding herself in a genderless society.
I am female. I was born that way. I have had those feelings, those longings, all of my life. It is not unnatural. I am not sick because I feel this way. I do not need to be helped. I do not need to be cured. What I need, and what all of those who are like me need, is your understanding. And your compassion. We have not injured you in any way. And yet we are scorned and attacked. And all because we are different. What we do is no different from what you do. We talk and laugh. We complain about work. And we wonder about growing old. We talk about our families and we worry about the future. And we cry with each other when things seem hopeless. All of the loving things that you do with each other - that is what we do. And for that we are called misfits, and deviants and criminals. What right do you have to punish us? What right do you have to change us? What makes you think you can dictate how people love each other?
(in response to macpye)
Season 5 Episode 17