Whenever from the sickness or infirmity of the person directed to be produced by any writ of habeas corpus such person cannot, without danger, be brought before the officer before whom the suit is made returnable, the party in whose custody he is may state the fact in his return to the writ, verifying the same by his oath; and if such officer is satisfied of the truth of such allegation and the return is otherwise sufficient, he shall proceed to decide upon such return and to dispose of the matter; and if it appears that the person detained is illegally imprisoned, confined or restrained of his liberty, the officer shall order those having such person in their custody to discharge him forthwith; and if it appears that such person is legally detained, imprisoned and confined, and is not entitled to be bailed, such officer shall dismiss the proceedings.
NMS § 44-1-26