Are there any rules for using can't and cannot since they mean the same thing, and they are used interchangeably, but they sound weird in certain contexts?
This answer at ELU suggests:
Grammatically, you can use can't instead of can not or cannot in the majority of circumstances. There is an exception. In wh-movement, the contraction should not be expanded unless you also change the word order:
Why can't I have some bacon? //OK
Why cannot I have some bacon? //not OK, archaic
Why can I not have some bacon? //OK again, although formal
Stylistically, the choice between can't and cannot is more complex. Generally, people use can't in speech and informal writing, and cannot or can not in formal writing or very formal speech. Also, cannot might be used when you need to carefully distinguish it from can't in speech.
I believe that this is up to speaker(writer)'s discretion. Though some do believe and claim that "can't" should not be used in formal speech or written form. Yet they are actually incorrect because negative question tags require the short form. E.g.: "He can help us, can't he?" "He can help us, cannot he?" just sounds like a pure evil...
Nevertheless, as the language rules get more and more relaxed you can find "can't" very often even in science papers/newspapers, etc... which is fine if you ask me.
side note: "can not" (though grammatically incorrect) is sometimes used in common speech if you put big emphasis on the 'not' part, e.g.: "You can NOT eat ice cream in the museum!" (In this case it would be clearly pronounced written as two words. Nobody would write it as "canNOT").
source: foreigner living the US