In a statement posted on Twitter, it said that it has "the cardinal responsibility of providing security for all Kenyans" and claimed the complex in eastern Kenya, which is the size of a large town, has become "a launchpad for various terrorist attacks by Al-Shabaab."
Earlier in the day, Judge John Mativo said in a ruling that closure of Dadaab violates the country's constitution.
The government's closure and repatriation plans are "arbitrary, discriminatory and undignifying and hence a violation of Articles 27 and 28 of the constitution and consequently the same is null and void," Judge Mativo declared.
The camp began to grow with the outbreak of instability and violence in Somalia in the early 1990s and is currently home to approximately 260,000 people.
Relief at court decision
Ahmed, 24, a refugee who was born in Dadaab, told CNN over the phone that the court's ruling this morning came as a relief.
"Ever since the government of Kenya said that the camp should close in six months we were just fearing that the government would say the six months is ended and each and every one should go. That was all we have been worrying about."
Human rights groups also applauded the court's decision.
"After months of anxiety because of the camp closure deadline hanging over their heads, increasingly restricted asylum options and the recent US administration suspension of refugee resettlement, the court's judgement offers Somali refugees a hope that they may still have a choice other than returning to insecure and drought-ridden Somalia," said Laetitia Bader, Africa researcher at Human Rights Watch, in a statement.
Somali refugees in Kenya affected by Trump's travel ban
Somalia was one of the country's included in US President Donald Trump's executive order to bar citizens of Iraq, Syria, Iran, Libya, Somalia, Sudan and Yemen from entering the US for 90 days. The ban also prevents entry for all refugees for 120 days.
Twenty-six thousand refugees in Kenya, most of them from Somalia, were affected by that ban, Yvonne Ndege, the spokeswoman in Kenya for the United Nations refugee agency, told CNN.
Somalia elects an "American" president
Yesterday, Somalia's Parliament elected former Prime Minister Mohamed Abdullahi Farmajo
, a dual US-Somali citizen, as the country's new president.
Farmajo was declared victorious after incumbent President Hassan Sheikh Mohamud dropped out of the contest following the second round of voting.
The 328 members of Parliament met at an air force hangar in Mogadishu to cast their votes because of fears of a terrorist attack.
With the doors to the US appearing to close, many Dadaab residents now wanted to go back to Somalia, according to Abdi Maalim, a freelance Kenyan-Somali journalist.
"Even the longest-staying refugees in the camp now have some hope in their country because of the new president who is very much seen as the people's president," he said.
Famine looms for 3 million Somalis
Maalim said those keen to return were largely from the cities, which have so far not been affected by a terrible drought that has gripped large swathes of Somalia.
The UN's Food and Agriculture Organization says up to three million people face hunger and even starvation because of poor rains that have wiped out crops and livestock.
"We are no longer talking about a drought crisis in Somalia, or even a severe drought crisis," FAO's Somalia Representative Dick Trenchard told CNN.
"We are talking about preventing famine in several areas of the country in the second half of the year, particularly in Bay in the south and Puntland in the north. Every Somali knows how bad the situation is and the potential catastrophe that lies ahead unless there is a massive and immediate increase in support and humanitarian assistance."
Kenyan human rights groups take lead
The high court ruling came in response to a petition not to shut Dadaab by two Kenyan human rights organizations, Kenya National Commission on Human Rights and Kituo Cha Sheria.
The camp was initially due to be closed on 30 November 2016, but the government announced a six-month delay on "humanitarian grounds."
Occupying about 50 square kilometers in Kenya's Garissa County, Dadaab has four sub-camps of Hagadera, Ifo, Dagahaley and Kambios, making it the largest refugee camp in the world by population.
The camps were initially designed to host just 160,000 people, yet the population rose dramatically between 2010 and 2013, mostly due to famine.
A spokesman for Kenya's Interior Ministry said the court's judgment did not impact an ongoing "voluntary" repatriation program that has already seen 46,000 Somali refugees return home over the past six weeks.