The judgment by Lords Ross, Cowie and Weir in favour of Strathclyde Region and its 12 successor authorities overturns two previous victories by the Scottish Secondary Teachers' Association at an industrial tribunal and the Employment Appeals' Tribunal.
The judges, who heard the final appeal by the councils in mid-June, have ruled that previous judgments misinterpreted the Equal Pay Act 1970, which the union used to bring a test case on behalf of 10 women members in Strathclyde.
The women were carrying out a principal teacher's work when no principal had been appointed and used male comparators to prove their case. The SSTA blamed Strathclyde's promoted post structure and the region's complex points system.
Craig Duncan, acting SSTA general secretary, said: "Obviously I am a bit gutted about the whole thing because the original decisions were so favourable. We will be seeking counsel's opinion about whether to appeal to the House of Lords and the decision will be made in late August."
The union will now incur substantial costs and even more if it appeals. But Mr Duncan said that would not be a factor in its decision. The Educational Institute of Scotland, along with the SSTA, is backing the cases of hundreds of secondary teachers.
Mr Duncan said: "The substance of our case has not been damaged by this and it is quite clear the present promoted post structure and the way people are asked to work cannot continue. We will have every justification to raise this as a matter of negotiation for the future."
Ian McPherson, the solicitor acting for the 12 councils, said: "I am absolutely delighted by the result. Along with counsel, I will be reviewing the judgment for other cases. There are implications that need to be addressed across Scotland because there are hundreds and hundreds of equal pay cases. "
Mr McPherson said the Court of Session's judgment could also have an effect on special school instructors in Strathclyde who have claimed parity with special education teachers. The industrial tribunal that ruled in the instructors' favour took the SSTA test case into account in reaching its judgment, Mr McPherson said.