Judges side against Scottish government’s bid to include transgender people in key law in a case with far-reaching implications.