The High Court judgement means the balance of power in the partially elected legislature swings further to the pro- China camp as opponents do not have enough seats to veto bills.
Former Umbrella Movement protest leader Nathan Law was among those barred in a case brought by the semi-autonomous city's Beijing-friendly government after the four changed their oaths of office to reflect frustrations with Chinese authorities.
Beijing issued a special interpretation of Hong Kong's mini-constitution, the Basic Law, in November to insist that oaths be taken in a "sincere and solemn" manner.
The High Court said Beijing's ruling was "binding" and that the court's decision to bar the four retrospectively was not politically motivated.
More From This Section
"The word 'solemn' bears the commonly understood meaning of being dignified and formal," the judgement said.
Concerns China is squeezing Hong Kong have sparked calls by some activists for self-determination or even independence for the city, angering Beijing.
The dismissed legislators were not staunchly pro- independence but at least two of them have advocated self- determination for Hong Kong.
Law's party Demosisto condemned "the manifest interference of the Beijing government to cripple Hong Kong's legislative power".
The 24-year-old was one of the most popular candidates to win a seat, gaining 50,000 votes to make him Hong Kong's youngest ever lawmaker.
He called on protesters to gather Friday night.
"Suppression is not scary," he told reporters.
"The most scary thing is that people get used to it and are not willing to come out, to fight."
Veteran anti-China lawmaker Leung Kwok-hung, known as "Long Hair", who was also barred, appeared to choke up as he said: "It's ironic that it's Bastille Day today."
The handover agreement enshrined liberties unseen on the mainland, including freedom of speech and an independent judiciary, but Beijing has been accused of trampling the deal by interfering in a number of areas, from politics to education and media.
Two pro-independence legislators have already been disqualified by the High Court over their oaths after they inserted expletives and draped themselves with "Hong Kong is not China" flags.
He was succeeded by Carrie Lam on July 1, who is also seen as a puppet of Beijing by critics.
The oath of office requires lawmakers to repeatedly describe Hong Kong as a Special Administrative Region of China.
Law quoted Gandhi before taking his pledge, saying: "You will never imprison my mind", and used intonation to make his oath sound like a question.
The judgement said Law "was objectively expressing a doubt on or disrespect of the status of the People's Republic of China as Hong Kong's legitimate sovereign country".
Former protest leader Lau Siu-lai failed to convey the oath's proper meaning by reading her pledge at a snail's pace, the court said.
Edward Yiu added lines to his oath, saying he would "fight for general universal suffrage", which rendered his pledge invalid according to the judgement.