The issue, one of the most significant facing the court this term, concerns the reach of Title VII of the Civil Rights Act of 1964 which, besides protecting against workplace discrimination because of race, religion and other characteristics, also prohibits discrimination "because of sex." The court has since interpreted that to include discriminating on the basis of sex stereotypes.
Lawyers for the gay and transgender individuals in the cases seemed to pitch their arguments at Justice Neil Gorsuch, who advocates a close reading of the text of the statute. During the sexual orientation arguments, he said sex seemed to be at least a "contributing cause" to the firings.
But during arguments in the transgender case, he asked "when a case is really close," whether courts should find that decisions that might cause "massive social upheaval" should be left to more explicit findings of the legislative branch.
Justice Brett Kavanaugh, the court's newest member, kept a low profile during the two hours of argument, asking few questions.
There seemed little doubt that the court's four liberal members would find that Title VII covered gay and transgender workers. But one of the court's five conservatives would have to join them to form a majority.
"At what point does a court continue to permit discrimination" rather than step in, asked liberal Justice Sonia Sotomayor.
The decision should be up to Congress, said Solicitor General Noel Francisco, representing the Trump administration. He said Congress almost annually turns away attempts to add sexual orientation and transgender status to the law.
The arguments touched on some of the most controversial issues of the day - whether it would mean the end of same-sex bathrooms, whether men should be able to compete on female athletic teams, whether dress codes for men and women would become a thing of the past.
The word "transgender" itself made its first appearance in a Supreme Court argument, as did cisgender and the gender-ambiguous "Pat" from old "Saturday Night Live" skits. Chief Justice John Roberts Jr. made a point of using the neutral "they" to refer to an individual.
The court combined two cases to consider whether gay workers are covered. Gerald Bostock claims he was fired from his job as a social worker in Clayton County, Georgia, after he became more open about being gay, including joining a gay softball league. Donald Zarda said he was fired as a skydiving instructor after joking with a female client to whom he was strapped for a tandem dive that he was gay. (Zarda died in 2014.)
Attorney Pamela Karlan, representing the two gay employees, told the court that firing a man for marrying another man, but not a woman for marrying a man, was clearly sex discrimination and covered by the law.
But Jeffrey Harris, the lawyer for the employers, distinguished between sex and sexual orientation, which he said are independent and distinct characteristics.
"That is just as true today as it was in 1964" when Congress passed the law, which he said did not include protections for gay people.
Justice Samuel Alito suggested that the court would be "acting exactly like a legislature" if it interpreted the law to prohibit discrimination on the basis of sexual orientation.
"You're trying to change the meaning of what Congress understood sex to be," Alito told Karlan.
Roberts Jr. asked the workers' attorney what new protections would mean for religious organizations. Karlan responded that exemptions already exist for those with religious objections to hiring gay workers.
Gorsuch asked about the implications for gender-specific uniforms and single-sex bathrooms.
The test, Karlan said, is whether there is a legal harm.
Justice Ruth Bader Ginsburg noted that "most people are not injured by having separate bathrooms. In fact, most people would prefer it."
The transgender case involves Aimee Stephens, who worked for years at a Michigan funeral home before being fired after informing the owners and colleagues of her gender transition.
American Civil Liberties Union legal director David Cole, representing Stephens, said the court will still face difficult questions about restrooms and athletic teams no matter how it ruled in these cases.
But he said Stephens's firing fit squarely within the law's wording "because of sex." She was fired, he said, "because she had a male sex assigned at birth."
John Bursch of the Alliance Defending Freedom, representing the funeral home, said the law does not require employers to treat men as women. It only means that one sex may not receive better or worse treatment than the other.
For 50 years, courts read the 1964 law to mean basically that, not that discrimination on the basis of sex included LGBTQ individuals. The Trump administration says that is what the Supreme Court should find as well.
In his brief to the court, Francisco said: "The ordinary meaning of 'sex' is biologically male or female; it does not include sexual orientation."
Employers violate Title VII only by treating members of one sex "worse than similarly situated members of the other sex. Discrimination on the basis of sexual orientation, standing alone, does not satisfy that standard," he wrote.
The government makes similar arguments against transgender status.
That puts the Trump administration at odds with the Equal Employment Opportunity Commission, which decided in 2015 that gay and transgender individuals were federally protected.
Treating a man who is attracted to men differently from a woman who is attracted to men is discrimination, the EEOC reasoned.
The commission also looked at a 1989 Supreme Court decision that said federal law protected against discrimination based on stereotypes; the court found for a woman who had not been promoted because her employers found her too aggressive and her manner of dress not feminine enough.
That is analogous to discriminating against a transgender individual, the commission said. And discrimination because of sexual orientation is the same thing, the EEOC said, because it relies on stereotypes about to whom men and women should be attracted.
Gay rights leaders say "married on Sunday, fired on Monday" is a possibility in more than half of the United States, where there is no specific protection for gay or transgender workers. The states that prohibit discrimination are not uniform - some protect only gender identity or transgender status, and some differentiate between public and private employment.
The sexual orientation cases are Bostock v. Clayton County, Georgia, and Altitude Express v. Zarda. The other case is R.G. & G.R. Harris Funeral Homes v. EEOC.
Sign up for the daily JWR update. It's free. Just click here.