If a party brought before the judge on the return of the writ is not entitled to discharge, and is not bailed where such bail is allowable, the judge shall remand the party to custody or place the party under the restraint from which the party was taken, if the person under whose custody or restraint the party was is legally entitled thereto.
NRS 34.550