A panel of three judges at the Court of Session found in favour of a cross-party group of politicians who were challenging the prime minister's move.
The judges said the PM was attempting to prevent Parliament holding the government to account ahead of Brexit.
A UK government appeal against the ruling will be heard by the Supreme Court in London next week.
The Court of Session decision overturns an earlier ruling from the court, which said last week that Mr Johnson had not broken the law.
The current five week suspension of Parliament, a process known as proroguing, started in the early hours of Tuesday.
MPs are not scheduled to return to Parliament until 14 October, when there will be a Queen's Speech outlining Mr Johnson's legislative plans. The UK is due to leave the EU on 31 October.
Opposition parties have called for Parliament to be immediately recalled in the wake of the court judgement, but Downing Street said this would not happen ahead of the Supreme Court's ruling on the case.
Downing Street also distanced itself from reports that quoted Number 10 sources as suggesting the Scottish judges were politically biased, and insisted that the prime minister has "absolute respect" for the independence of the judiciary.
What did the Scottish judges say?
Mr Johnson had previously insisted that it was normal practice for a new government to prorogue Parliament, and that it was "nonsense" to suggest he was attempting to undermine democracy.
But the Court of Session judges were unanimous in finding that Mr Johnson was motivated by the "improper purpose of stymieing Parliament", and he had effectively misled the Queen in advising her to suspend Parliament.
They added: "The Court will accordingly make an Order declaring that the prime minister's advice to HM the Queen and the prorogation which followed thereon was unlawful and is thus null and of no effect."
Read More (...)