But British Foreign Secretary Liz Truss, in a report to parliament, said "the political and legal situation in Hong Kong has now deteriorated beyond the point where it is acceptable for serving UK judges to take part".
The judges resigned from the Hong Kong Court of Final Appeal (CFA) on Wednesday, saying they could not support an administration that had "departed from values of political freedom" and freedom of expression.
Hong Kong returned to Chinese rule in 1997 with the guarantee of a high degree of autonomy, including an independent judiciary and freedom of speech.
Britain says the national security law is a breach of the 1984 Sino-British Joint Declaration that paved the way for the city's return to China under a "one country, two systems" formula.
Chinese Foreign Ministry spokesman Wang Wenbin expressed "strong dissatisfaction" with the resignations and said British pressure had been exerted on the judges in order "to defame the Hong Kong National Security Law and interfere in China's internal affairs".
"The British side flagrantly interfered in and undermined the administration of justice in the territory by political means," he told reporters.
British judges have long served among the foreign jurists appointed to the CFA, an arrangement to maintain confidence in a separate legal system widely seen as the bedrock of the city's social and commercial freedoms.
Business people and diplomats are watching particularly closely, given the importance of legal independence to Hong Kong's status as a global financial hub.
Robert Reed, the head of Britain's top judicial body, on Wednesday said he and colleague Patrick Hodge would relinquish with immediate effect their roles as non-permanent judges on the CFA. Reed's statement said the move was made in agreement with the British government.
"With Beijing assuming almost complete control of Hong Kong's law-making process, the judiciary is now being required to enforce Beijing's laws and the values they contain," Truss wrote in a six-monthly report to parliament.
"Such laws are not aligned with UK values. By taking this decision, we are standing up for the principles of freedom and democracy."
Hong Kong leader Carrie Lam said she regretted the resignations, adding that foreign judges were much valued to help safeguard judicial independence.
"I remain very confident that we still have very fine judges in the judiciary, both local and from overseas. Hong Kong will continue to benefit significantly," she said.
Neither Reed nor Hodge could immediately be reached for comment.
The national security law, which punishes offences like subversion with up to life imprisonment, has drawn widespread criticism from pro-democracy politicians in Hong Kong and from Western countries, including the United States and Britain.
The U.S. State Department on Thursday said in a report on conditions in Hong Kong that Chinese and Hong Kong authorities in the past year "repeatedly took actions that eroded the judiciary's independence and ability to uphold the rule of law."
Many of the city's democratic campaigners have been arrested, detained or forced into exile, civil society groups have shut down and liberal media outlets forced to close in a security crackdown following the introduction of the law.
Lam and the Hong Kong government deny that the law, introduced after months of at times violent pro-democracy demonstrations, curbs freedoms, saying it was necessary to maintain order, preserve the city's economic success and guard against foreign interference.
Lam pointed out that the law does not prohibit overseas judges from serving and hearing security cases, adding that judges' independence meant that foreign judges, either by their oath or judgments, in no way endorsed her government.
Reed said earlier that while Hong Kong's courts were respected for their commitment to the rule of law, judges could not serve in the city "without appearing to endorse an administration which has departed from values of political freedom, and freedom of expression, to which the justices of the Supreme Court are deeply committed".
Ten other foreign judges are still serving the Hong Kong court, six of whom are retired British jurists.
Canada's former top judge, Beverley McLachlin, is to remain serving on the CFA, Lam said, citing her as saying her appointment had no connection to the Hong Kong administration.
Retired former Australian Chief Justice Robert French told Reuters in an email he and his two Australian colleagues would stay on the bench.
"We do not intend to resign. We support the judges of the CFA in their commitment to judicial independence," he said, referring to former justices William Gummow and Murray Gleeson.
Gummow and Gleeson did not immediately respond to requests for comment.