The UK government acted lawfully when it used its previously untested power of veto over the Scottish government’s gender recognition reform bill, a judge at Scotland’s highest court has ruled, in a major legal battle over the twin flashpoints of constitutional powers and gender recognition.