If the judge, under section 589.12, finds no legal cause to support imprisonment or restraint of the petitioner, the judge shall discharge the petitioner.