I do not view punctuation and capitalization as technically part of grammar because they do not even exist in the spoken language. They are conventions of formal writing specified in style guides. According to those conventions, the spelling “sally” is an error if it is intended as a proper name. However, I believe that, if “sally” is intended as a proper name, then
The president thinks sally is a sandwich
is grammatical because it follows the same structure as
The president thinks sally is a senator
which second sentence, if spoken aloud, would be considered grammatical by anyone familiar with English grammar. Indeed, the “sandwich” sentence would not raise an eyebrow in certain contexts, e.g.,
The president has become psychotic and is so far around the bend that now thinks Sally, who has been his wife for thirty-six years, is a sandwich.Sally’s bite marks have needed medical treatment.
If “sally” is not intended as a proper name, the indicated sentence is not grammatical.
Of course, not everyone agrees that capitalization and punctuation are just conventions of formal writing and thus not technically part of grammar. In that case, spelling the proper name “Sally” as “sally” is a gross violation of English grammar.
Grammatical examples that, absent context, assert nonsense are bad examples because it is hard to separate content from form. Nevertheless, grammar is about form rather than content.
The A thinks that X is a P
is a grammatical form.
All this proves is the rather obvious truth that one can speak nonsense grammatically and sense non-grammatically. Grammar and sense are different realms.