Gay workers and their corporate supporters won a legal victory over the Trump administration as a federal appeals court ruled that firing people over their sexual orientation is a form of illegal sex discrimination.

The appeals court in Manhattan overturned its own previous rulings, saying “legal doctrine evolves.” It’s the second ruling in the U.S. to break with precedent in finding that workplace discrimination based on sexual orientation is illegal. A third appeals court ruled the other way last year....