The Seoul Central District Court said in a statement that its ruling was based on the timing of the indictment that came after the initial detention period had expired, and noted "questions about the legality" of the investigation process that involved two separate agencies.
On January 15, Yoon became the first sitting president to be arrested on criminal charges after days of a standoff between presidential guards and arresting authorities.
"The court's decision to cancel the arrest showed this country's rule of law is still alive," Yoon's lawyers said in a statement.
Yoon's lawyers also said he may not be immediately released because prosecutors can appeal. The prosecutors' office did not immediately comment on the ruling.
The defence team had argued that a warrant issued on January 19 that extended Yoon's detention was invalid because the request filed by prosecutors was procedurally flawed.
Yoon saidhis December 3 martial law declaration was needed to root out "anti-state" elements but lifted the decree six hours later after parliament voted to reject it. He has said he never intended to fully impose emergency military rule.
Weeks later he was impeached by the opposition-led parliament on accusations he had violated his constitutional duty by declaring martial law.
The Constitutional Court is expected to rule soon on his impeachment.
