Penal Code PC § 2684
(a) If, in the opinion of the Secretary of the Department of Corrections and Rehabilitation, the rehabilitation of any mentally ill, mentally deficient, or insane person confined in a state prison may be expedited by treatment at any one of the state hospitals under the jurisdiction of the State Department of State Hospitals or the State Department of Developmental Services, the Secretary of the Department of Corrections and Rehabilitation, with the approval of the Board of Parole Hearings for persons sentenced pursuant to subdivision (b) of Section 1168 , shall certify that fact to the director of the appropriate department who shall evaluate the prisoner to determine if he or she would benefit from care and treatment in a state hospital. If the director of the appropriate department so determines, the superintendent of the hospital shall receive the prisoner and keep him or her until in the opinion of the superintendent the person has been treated to the extent that he or she will not benefit from further care and treatment in the state hospital.
(b) Whenever the Secretary of the Department of Corrections and Rehabilitation receives a recommendation from the court that a defendant convicted of a violation of Section 646.9 and sentenced to confinement in the state prison would benefit from treatment in a state hospital pursuant to subdivision (a), the secretary shall consider the recommendation. If appropriate, the secretary shall certify that the rehabilitation of the defendant may be expedited by treatment in a state hospital and subdivision (a) shall apply.