When someone is non compos mentis, they are not sane or rational. When a person is declared by a judge to be non compos mentis, they can’t legally speak for themselves.
You can use this Latin phrase to describe someone who isn’t right in the head, either because they have a long-term mental illness, or simply because they’re confused, injured in a way that affects their thinking, or intoxicated. It’s more often used in a legal context, usually to officially label a person who isn’t able to testify in court or defend themselves. Non compos mentis literally means “not master of one’s mind.”