Judge Lady Haldane said that the definition of sex was "not limited to biological or birth sex".
She said it could also include people with a gender recognition certificate after changing their legally recognised gender.
The judge also stated that sex and gender reassignment were separate and distinct characteristics but were not necessarily mutually exclusive.
In her decision, Lady Haldane wrote: "I conclude that in this context, which is the meaning of sex for the purposes of the 2010 Act, 'sex' is not limited to biological or birth sex, but includes those in possession of a GRC obtained in accordance with the 2004 Act stating their acquired gender, and thus their sex."
The judgement comes the week before controversial Scottish government plans to make it easier for people to change their legally recognised gender are due to face a final vote at Holyrood.
🏳️⚧️🤝🏴