Mr. El-Zakzaky was arrested by the military on December 14, 2015, after a clash between the movement and officers of the Nigerian army.
The army killed at least 347 members of the group.
Mr. El-Zakzaky approached the court to demand his release, months after he was arrested without being charged to Court.
He asked the Court to declare that his arrest and continued detention violated his fundamental rights.
His lawyer, Femi Falana, said the court should declare that the continued detention of his client without charging him, was unlawful.
Delivering the judgement, Justice Gabriel Kolawole, rejected the submission of the counsel to the State Security Service, Tijjani Gazali, that Mr. El-Zakzaky was kept in protective custody of the SSS.
He said the decision to hold the Islamic cleric and his wife for their safety was not based on law.
“I have not been shown any incident report or any complaint lodged by residents around the neighbourhood that the applicant has become a nuisance to his neigbourhood,” said the judge.
He said the decision of the government to hold the applicant for so long amounted to great danger.
Citing the death of former leader of the Boko Haram leader, Mohammed Yusuf, the judge said; “If the applicant dies in custody which I do not pray for, it could result in many needless deaths”.
Mr. Kolawole said the government should within 45 days release the applicant and his family to the police, who shall within 24 hours take them, guarded by escort, to a safe place.
He added that the SSS will pay a fine of N25 million each to Mr. El-Zakzaky and his wife, making N50 million.