A person properly imprisoned or restrained by virtue of the legal judgment of a competent tribunal of civil or criminal jurisdiction, or by virtue of an execution regularly and lawfully issued upon that judgment or decree shall not be allowed to prosecute the writ.