I didn't know whether to put this is the movie forum or here, so I just chose here. I accept both the TV episode "Relics" and the later movie Generations in my personal Trek canon. Since Generations came out, I am not aware that there have any been any official explanation as to why Scotty thought it was Kirk who had come to rescue him chronologically after Kirk apparently died on the Enterprise-B.
So has anyone come up with any retcons to explain it?
Actually yes, Ron Moore said at the time that he knew this was an inconsistency, but that Scotty was included in the film out of simple affection for the character. I no longer remember where I read this, unfortunately.
As for an "in-universe" explanation, it could be explained away that Scotty got lost in the transporter after Kirk "died" on the B, and 75 years in suspended animation scrambled his memory a little.
Works for me.