At any point in history was "Why cannot...?" used as frequently as "Why can't...?" Is it even grammatically correct to say "Why cannot you do this?" I know it can be rearranged to be "Why can you not do this?," but I always presumed the contraction and the contracted phrase could be used equivalently, without changing the sentence structure. I think this pattern holds true with the other question words (e.g. how, when, etc.); however, I also know it is common to say "Who cannot do this?" In general, are there rules pertaining to the uses of contractions in questions?
The transition point was about a century ago
Note that if we substitute a pronoun (I, he, they) for "why", the transition point comes much later (1980 for "I") – or hasn't even happened yet (all other pronouns). I can't explain why that is, except by pointing out that this very sentence is an increasingly typical usage. Maybe we all tend to be a bit less formal when introducing our own selves into the text.
It's only my opinion, but I think can't (similarly, let's) are examples of grammaticalisation. The contracted form has effectively taken on a "life of its own", leading to a situation where OP is prepared to accept that there may be contexts where can't is "grammatical", but "cannot" (or the equivalent "can not") wouldn't be valid.
Using cannot / can not might be a bit stilted in many contexts now we're so used to seeing the contracted form, but I don't think it's ever ungrammatical.
Arnold M. Zwicky and Geoffrey K. Pullum have shown that -n't is not just a contraction of not. The two American linguists pointed out that you can say why don't you... but not *why do not you... because you can place one and only one auxiliary before the subject in an interrogative phrase. Don't is a single word while do not are two words. -n't is not a clitic but a negative inflectional suffix.
Cannot is the only negative form that contains not rather than -n't. Theoretically, since it is a single word, you can say why cannot you... without a problem. My theory is that modern English speakers don't want to put cannot before the subject because it contains not and sounds like can not. You definitely cannot say why can not you... with a separate not. On the contrary can't remains a single word, which is why they use it more and more often.