The landmark case cements the dramatic changes the security law has begun making to semi-autonomous Hong Kong's common law traditions as Beijing seeks to snuff out dissent in the restless financial hub.
Lai, the 73-year-old owner of pro-democracy tabloid Apple Daily, is one of some 100 activists arrested under the law since it was enacted in June, and the highest-profile figure to be placed in pre-trial custody.
He has been charged with "colluding with foreign forces" -- one of the new security crimes -- for allegedly calling for sanctions against Hong Kong and China.
The security law is the most pronounced shift in Hong Kong's relationship with China since it was handed back by Britain in 1997.
It criminalised a host of political views and toppled the legal firewall between the two territories.
Written in Beijing and imposed by fiat, it allows mainland security agents to operate openly in the city for the first time, and even grants China jurisdiction in some cases.
Tuesday's ruling by the Court of Final Appeal centred around bail.
Presumption of bail for non-violent crimes is a hallmark of Hong Kong's legal system.
But the national security law removes that presumption and says judges have to be sure a defendant "will not continue to commit acts endangering national security".
Lai was detained in December and released on bail for about a week after a lower court granted him HK$10 million (US$1.3 million) bail together with a stringent list of requirements, including house arrest, no interviews and no social media posts.
But he was put back behind bars after the prosecution sought to challenge those bail conditions.
On Tuesday, a panel of five senior judges ruled in favour of the prosecution and said that the lower court judge had erred in granting Lai bail.
The security law, the judges wrote, "creates such a specific exception to the general rule in favour of the grant of bail and imports a stringent threshold requirement for bail applications".
The judges said Lai could make a fresh bail application in the lower courts which would have to take into account their directions.
Legal analysts were closely watching the case for an indication of whether Hong Kong's judiciary will serve -- or even can serve -- as any kind of constitutional brake against Beijing's security law.
The judiciary can only interpret laws, which are usually passed by Hong Kong's semi-elected legislature.
During challenges to new legislation, judges balance the wording of the law against common law traditions and core liberties that are enshrined in Hong Kong's mini-constitution and its Bill of Rights.
But the national security legislation was penned directly by Beijing and looks set to trump any other legislation in the event of a dispute.
Bail is not the only area where legal precedents are changing under the security law.
On Monday, AFP revealed authorities have opted not to use a jury for the first national security trial, according to a legal source with direct knowledge, citing security concerns for jury members.
Asked about that decision on Tuesday, Hong Kong's leader Carrie Lam replied: "I will not comment on individual cases which are now under the judicial process."
Challenging the security law in court may be tricky.
In Hong Kong's complex constitutional hierarchy, the ultimate arbiter of the laws is Beijing's Standing Committee, which has shown an increased willingness in recent years to wade into legal arguments and make pronouncements.
China's state media have already declared Lai guilty and made clear authorities expect Hong Kong's judges to side with Beijing on national security.
In a tweet, China's state-run Global Times hailed Tuesday's Lai ruling, describing him as a "major secessionist".
Senior Chinese officials have recently backed calls to "reform" Hong Kong's judiciary, something opponents fear signals support for a more mainland-style legal system that answers to the Communist Party and where convictions are all but guaranteed.
One of the key problems today is that politics is such a disgrace, good people don't go into government.