A defendant found guilty of an offense, or the prosecuting attorney may, within ten days after the defendant is found guilty, and prior to the time the defendant is sentenced, file a motion for a hearing on the present mental condition of the defendant if the motion is supported by substantial information indicating that the defendant may presently be suffering from a mental disease or defect for which he is in need of custody for care and treatment in a suitable facility. The court shall grant the motion, or at any time prior to the sentencing of the defendant shall order such a hearing on its own motion, if it is of the opinion that there is reasonable cause to believe that the defendant may presently be suffering from a mental disease or defect for which he is in need of custody for care or treatment in a suitable facility.
SDCL 23A-27-42