In addition to the requirements of §§ 23A-7-4 and 23A-7-5, if a defendant charged with a felony pleads guilty but mentally ill, the court may not accept the plea until the defendant has been examined by a licensed psychiatrist or a court-approved licensed psychologist and the court has examined the reports. The court shall hold a hearing on the defendant's mental condition and, if there is a factual basis on which the court can conclude that the defendant was mentally ill at the time of the offense, the plea shall be accepted.
SDCL 23A-7-16