Judge Yusuf Haliru said the detention of Col. Nicholas Ashinze was illegal.
Ashinze was aide to former presidential security adviser Sambo Dasuki, who also was arrested in December on allegations of diverting USD 2.9 billion meant to buy arms to fight the Boko Haram insurgency.
Three different courts have ordered Dasuki's release but President Muhammadu Buhari has said he must stay in jail.
Human rights groups say some judges and lawyers are corrupt.