On the return of a writ of habeas corpus issued pursuant to this chapter and the production of the person detained, the court or judge shall immediately inquire into the legality and propriety of the confinement or detention. If it appears that the person is detained without legal warrant or authority, the court or judge shall immediately release or discharge him. If the court or judge deems his detention to be lawful and proper, the court or judge shall remand him to the same custody, or, in a proper case, admit him to bail, if he is confined on a charge of having committed a bailable criminal offense. If he is bailed, the court or judge shall require a sufficient bond or recognizance to answer in the proper court, and transmit it to that court.
D.C. Code § 16-1906