"of sound mind, mentally sound," 1721, a back-formation from insane or sanity or else from Latin sanus "sound, healthy," in its figurative or transferred use, "of sound mind, rational, sane," also, of style, "correct;" a word of uncertain origin.
It is perhaps from PIE *seh-no- from *seh- "to tie." That reconstruction "is purely mechanical," according to de Vaan, the meaning might be "which is in place, in order." Or it could be from a different root meaning "to satisfy" as in Latin satis "enough."
Used earlier, of the body, with a sense of "healthy" (1620s), but this has been rare in English. OED writes, "The almost entire restriction in English to a sense 'mentally sound' is due to the use in antithesis with insane, which (like the Latin insanus, its source) always referred to mental condition." Related: Sanely; saneness.
1846, "capable of being declared as true," from certify + -able. Meaning "so deranged as to be certifiably insane" is recorded from 1870, from certify in the specific sense "officially declare (someone) to be insane" (1822). The certification was done by local officials, later medical officers, and often included a statement as to whether the person was harmless or dangerous, curable or incurable.
c. 1790, of persons, "insane, disordered in the mind;" of things, "out of order," from 1796; past-participle adjective from derange (v.).
"make furious, enrage," also "be out of one's mind," late 14c., from Old English gemædan "make insane" (see mad (adj.)).