In any proceeding under subsection a., b., or c. of N.J.S. 2A:67-13, if no cause is shown for the imprisonment or restraint or for the continuation thereof, the judge shall discharge the party from the confinement or restraint. If the party is not entitled to a discharge and is not bailed, the party shall be remanded by the judge to the custody or placed under the restraint from which the party was taken, so long as custody or restraint is lawful. If the custody or restraint is not lawful, the judge shall commit the party to the custody of the officer or person lawfully entitled thereto.
In any proceedings under subsection a., b., c., or d. of N.J.S. 2A:67-13, if it appears that the person is entitled to be bailed, the judge shall discharge the person immediately, upon taking a secured or bonded recognizance in an amount as the judge may approve for the person's appearance, as the circumstances may require, and the judge shall then certify the writ with the return and the recognizance to the court where the appearance is to be made.
In any proceeding under subsection d. of N.J.S. 2A:67-13, the judge shall discharge the party in custody if the process was improperly or improvidently issued.
In any proceeding under subsection e. of N.J.S. 2A:67-13, the person shall not be discharged unless found not to be dangerous to self or dangerous to others or to property, either by the judge, if the hearing is held without a jury, or by unanimous verdict of the jury.
No person shall be entitled to a discharge because of any informality or insufficiency in the original arrest or commitment.
N.J.S. § 2A:67-29