Should the presence of any prisoner confined, under authority of RCW
72.68.040 through
72.68.070, in an institution of another state or the federal government or in a county or city jail, be required in any judicial proceeding of this state, the superintendent of a state correctional institution for convicted felons or his or her assistants shall, upon being so directed by the secretary, or upon the written order of any court of competent jurisdiction, or of a judge thereof, procure such prisoner, bring him or her to the place directed in such order and hold him or her in custody subject to the further order and direction of the secretary, or of the court or of a judge thereof, until he or she is lawfully discharged from such custody. The superintendent or his or her assistants may, by direction of the secretary or of the court, or a judge thereof, deliver such prisoner into the custody of the sheriff of the county in which he or she was convicted, or may, by like order, return such prisoner to a state correctional institution for convicted felons or the institution from which he or she was taken.