The case, brought to the court by Kituo Cha Sheria, an NGO that provides legal aid to Somali refugees and the Kenya National Commission on Human Rights, found that the closure of the camp, which would force Somali refugees to return home, would endanger the lives of those returning.
A government plan to close the world's largest refugee camp has been blocked by Kenya's highest court.
Judge John M. Mativo said in the judgment Thursday that the plans to close Dadaab and repatriate Somali refugees violate the worldwide legal principle of non-refoulment, described in the 1951 Refugee Convention.
Human rights groups welcomed the decision to overturn the closure, but the government said it would appeal the decision.
Locator map of Dadaab refugee camp in Kenya.
Amnesty International, among the groups which challenged the government's actions, said the closure of Dadaab would have left more than 260,000 Somali refugees with nowhere to go.
The Government also disbanded the Department of Refugee Affairs, which worked with humanitarian organizations for the welfare of the refugees. "This ruling reaffirms Kenya's constitutional and global legal obligation to protect people who seek safety from harm and persecution", she added.
Since sending troops into neighbouring Somalia in 2011, Kenya has come under repeated attack from Al-Qaeda-linked Shabaab militants.
The sprawling Dadaab complex near the border with Somalia now houses about 256,000 people compared to 320,000 in mid 2016.
In October 2016, MSF released a report 'Dadaab to Somalia: Pushed Back Into Peril,' in which more than eight out of ten refugees surveyed said they did not want to return to Somalia, with the main concerns cited including fear of forced recruitment into armed groups, sexual violence and the non-availability of healthcare.
The Kenyan government's reason for closing the camp was premised on security.
The court decision came a day after a former Somali prime minister and dual US citizen, Mohamed Abdullahi Farmajo, was announced the victor of the country's long-delayed presidential elections.
The orders are excessive, arbitrary and disproportionate, he said.
MSF has described the ruling as a positive step for the scores of refugees who have been stuck in limbo since the official announcement was made. We hope to see successful refugee hosting models like that followed in Uganda - where refugees are allowed to support themselves, use local health and education services, and contribute to their communities - replicated across East Africa and beyond.