Sanity, sane, sanitation, sanitary. The words for mental soundness and the ones for purification sound alike. Being insane is being unsanitized.
Yes, they do indeed come from the same word, the classical Latin sanus, which means healthy or sane. As to why they have a dual meaning, I can’t say. Sanity came first, showing up in the early fifteenth century with the meaning of health in its Middle French and Latin forms. At the time, “sanity” referred to both physical and mental health, and then when the mind became considered to be independent of the body, just mental.
Similarly, sane showed up in 1721, also referring to the body and not the mind. Sanitary, however, kept the old “health” meaning of the word even though it was the last of the words to show up. It didn’t appear until 1842, less than two hundred years ago.
So that answers that. And for the record, you don’t want to Google “mental health in the Middle Ages”. It’s…horrifying.
Online Etymology Dictionary’s pages on sane, sanity and sanitary.