The judge ruled that the granting of consent had failed to take into account a European Union directive concerning rare birds in relation to whimbrel nesting on the island.
Significantly, she also said that the Scottish government should not have granted consent until the project had been issued with an electricity generating licence.
This could have potential ramifications for future projects if the ruling is upheld. It is standard practice to apply for an electricity generating licence once a project has been been granted consent, known as planning permission in the UK.
Only eight of 53 applications currently being considered by the government are known to have been granted a generating licence by regulator Ofgem.
The judicial review was brought by anti-wind group Sustainable Shetland. The Scottish government has said it will appeal the decision.
"Ministers do not agree that the application was incompetent under schedule 9 of the Electricity Act, nor do they agree that they failed to take proper account of their obligations under the EU wild birds directive," said a Scottish government spokesperson.
UK secretary of state for energy and climate change Ed Davey announced only last month that a higher strike price would be paid for projects on remote Scottish islands to account for higher development costs.
The project is 50% owned by utility SSE. The other half is held by Viking Energy, which is 90% owned by community organisation Shetland Charitable Trust.
The Viking wind farm is a key part of Scotland's target of producing all of its domestic energy through renewables by 2020, and its collapse would be seen as a blow to this ambition.
The project would feature 103 turbines with a 3.6MW capacity. The Siemens 3.6MW is the most likely choice, but this has not been confirmed.