If a defendant who has been found to be not competent to stand trial believes that he or she can establish a defense of not guilty to the charges pending against him or her, other than the defense of not guilty by reason of mental illness, the defendant may request an opportunity to offer a defense thereto on the merits before the court which has criminal jurisdiction. If the defendant is unable to obtain legal counsel, the court of record shall appoint counsel for the defendant to assist him or her in supporting the request by affidavit or other evidence. If the court of record in its discretion grants the request, the evidence of the defendant and of the state shall be heard by the court of record sitting without a jury. If after hearing the petition the court of record finds insufficient evidence to support a conviction, it shall dismiss the indictment and order the release of the defendant from criminal custody. The release order, however, may be stayed for 10 days to allow civil commitment proceedings to be instituted by the prosecutor pursuant to §27-5-1 et seq. of this code: Provided, That a defendant committed to a mental health facility or state hospital pursuant to §27-6A-3 (d) or §27-6A-3 (f) shall be immediately released from the facility unless civilly committed.
W. Va. Code § 27-6A-6