A group of 27 church leaders launched a judicial review at the Court of Session arguing the Scottish government acted beyond their emergency powers.
Lord Braid agreed the regulations went further than was lawfully allowed.
The ruling was issued with "immediate effect" so churches - but also mosques, synagogues and temples - can open now.
It comes just two days before communal worship is due to resume under the next phase of lockdown easing.
Lawyers for the Scottish government had argued that it was forced to make the changes as the Kent variant of Covid was more transmissible.
The Scottish government said it would carefully consider the findings and its implications.
Lord Braid said those who brought the judicial review were entitled to have the regulations declared unlawful.
He said the Scottish government regulations disproportionately interfered with the freedom of religion secured in the European Convention on Human Rights.
He added: "It is impossible to measure the effect of those restrictions on those who hold religious beliefs. It goes beyond mere loss of companionship and an inability to attend a lunch club."
However, the judge emphasised that he was not saying that coming together for worship was safe.
"I have not decided that all churches must immediately open or that it is safe for them to do so, or even that no restrictions at all are justified," he said.
"All I have decided is that the regulations which are challenged in this petition went further than they were lawfully able to do, in the circumstances which existed when they were made."
Rev Dr William Philip, senior minister at the Tron Church in Glasgow, welcomed the ruling.
He said: "From the outset we have recognised the serious decisions the Scottish Ministers had to take in response to the pandemic.
"However, its approach to banning and criminalising gathered church worship was clearly an over-reach and disproportionate and if this had gone unchallenged it would have set a very dangerous precedent.
"However well intentioned, criminalising corporate worship has been both damaging and dangerous for Scotland, and must never happen again."
Andrea Williams, chief executive of the Christian Legal Centre, said she was "thankful and relieved" that the court had recognised what she described as a "dangerous interference".
She added: "The fundamental principle of freedom has prevailed with a strong dash of good old common sense."
Additional party Canon Tom White's argument that the regulations were disproportionate on constitutional grounds was also found to be the case by Lord Braid.
Canon White, parish priest of St Alphonsus Church in Glasgow, said: "I'm overjoyed to hear that the court has understood the essential need to protect not only the physical and material health of our society but also its spiritual needs and therefore overturned the disproportionate, unnecessary and unlawful blanket ban on public worship."
On hearing that the restrictions would be lifted immediately, Canon White confirmed he would hold a Covid-safe Mass at St Mary's RC church in the east end of Glasgow on Thursday morning.
Communal worship was already due to resume from Friday in time for Passover, Easter, Ramadan and Vaisakhi.
Up to 50 people will be able to attend if the place of worship is large enough to facilitate 2m social distancing, an increase from the limit of 20 people which had applied pre-lockdown.
A Scottish government spokeswoman said: "We acknowledge this opinion and will now carefully consider the findings, its implications, and our next steps. Court proceedings are ongoing and it would be inappropriate to offer any further comment at this stage."