The court of the West African bloc called for Bazoum's "immediate and unconditional release" and ordered that he be reinstated, according to the judge in the case heard in Nigeria's capital Abuja.
Niger is currently suspended from ECOWAS. Other member states have, in the past, ignored rulings from the ECOWAS court.
"It is Mohamed Bazoum who represents the state of Niger... he remains president of the republic," the court ruling said.
"There are constitutional rights that have been violated."
Bazoum has been held in his presidential residence with his wife and their son since he was overthrown.
In mid-September, the deposed president appealed to the ECOWAS Court of Justice to obtain his release and the restoration of constitutional order in the country.
Coup leaders agree to transition terms
The ruling military agreed to the terms and conditions of a transition back to civilian rule and will present the plan to a regional bloc, the chief diplomat from mediator Togo announced Thursday.
Speaking on Niger's national television, Togo Foreign Minister Robert Dussey said he had reached an agreement "on the content and timing of the transition" with Niger's junta-appointed Prime Minister Ali Mahaman Lamine Zeine and Foreign Minister Bakary Yaou Sangare.
"We are ready to present the plan ... to the mediating heads of state and the ECOWAS Commission," he said.
ECOWAS decided that a committee made up of the presidents of Benin, Togo and Sierra Leone would lead negotiations with the Nigerien military leaders on the commitments to be implemented.
The bloc has imposed tough sanctions on Niger and suspended trade, while also floating the option of military intervention.
The sanctions and suspension of international finance and aid have left Niger, already one of the world's poorest countries, economically hanging by a thread.
On Sunday, ECOWAS leaders in Abuja said any easing of the punitive measures against Niger was contingent on a "short transition" period.
Niger's military leaders have previously said they want up to three years for a transition back to civilian rule.
Forum