In Arizona we have what we call Rule 11. Ie: Rule 11 of the Arizona Rules of Criminal Procedure governs the mental capabilities of the defendants.
The standard is pretty long, but basically a defendant must be mental fit enough to assist his attorney in his own defense. He must be able to recognize what the judge & attorneys do, what a plea offer is, etc.
If the defense attorney (and sometimes the prosecutor) feels that a defendant may be "Rule 11", they will ask the judge to have the defendant examined. This is a pre-screen done by a shrink. If he feels futher examination is necesarry, the state and the defense will both pick shrinks, one of which must also be an MD, to examine the defendant, his background, the case, etc. Both docs will file their findings with the court.
A defendant will either be found competant to stand trial, incompetant but restorable or incompetant and not restorable.
Competant means he can stand trial
Incompetant but restorable means that he will receive treatment until he can be tried.
Incompetant and not restorable means that charges cannot be held against him. He may be release, but usually he will be committed to some type of treatment facility.
Long answer is that I would guess less than 7% of defendants meet this standard. And of all the defendants we see, less than that are actually "mentally retarded".