The High Court in Nairobi has temporarily blocked government from repatriating refugees and asylum seekers dwelling at Kakuma and Dadaab camps.
Justice Anthony Mrima issued the order following a petition filed by rights advocacy group Kituo Cha Sheria, challenging Interior minister Fred Matiang'i's announcement on the government's intention to shut the two refugee camps.
The two host more than 400,000 people mainly from Somalia but also from countries such as South Sudan and Ethiopia.
The judge directed consolidation of the petition with another one filed earlier by former presidential aspirant Peter Gichira on April 8, and in which a court suspended the closure of the camps.
The two orders - against closure of the camps and repatriation of the refugees - will remain in force until July 7 when the cases will be mentioned for directions.
Kituo Cha Sheria says the proposed closure of the camps and repatriation of refugees to their countries of origin violates their right to human dignity, freedom and security of persons, as stated under articles 27, 28 and 29 of the Constitution of Kenya.
The group further notes that the refugees fled persecution, serious human rights violations, conflict and other serious harm from neighbouring countries such as Somalia, Ethiopia, Democratic Republic of Congo, Burundi, South Sudan, Sudan, Eritrea and Uganda.
The refugees and asylum seekers have predominantly been hosted at Dadaab and Kakuma camps which were established in 1991 and 1992, respectively.
Kituo Cha Sheria wants the court to declare that the government's decision amounts to collective punishment and is illegal, discriminatory, and therefore unconstitutional.
The case has been supported by Ms Debrah Thomas Kashindi, a refugee from South Kivu Congo, who says in an affidavit that her country has been stifled by a non-international armed conflict for several years.
She sought asylum in Kenya in February 2014 after fleeing the conflict in her country and has been residing at Kakuma, where she depends on humanitarian agencies for protection and assistance as she does not have any means or source of livelihood.
"There has been fighting in the eastern area of the Democratic Republic of Congo between forces of rebel groups and those of other African countries, including Rwanda and Uganda," she says.
"Over time, the government of the Democratic Republic of Congo has lost control over most of the areas in eastern parts of the Democratic Republic of Congo which are controlled by rebel groups,."
She adds that the Refugee Affairs Secretariat has neither cancelled nor revoked her refugee status and also hasn't voluntarily taken any action to bring her refugee status to an end.
On March 24, Cabinet Secretary Matiang'i announced the closure of the refugee camps, giving the United Nations refugee agency (UNHCR) two weeks to present a plan to do so.
Citing terror threats planned from the two camps, the minister said there was no room for further negotiations.
The government first announced its intention to shut the Dadaab camp, which is closer to the border with Somalia, back in 2016 following national security concerns.
The move was informed by intelligence reports, which showed two terror attacks in 2013 and 2015 took place with the involvement of elements within the camps.