SNP loses court battle