There are several explanations offered by the show's principals.
Continuity is not king
In an AOL chat, showrunner Ronald D. Moore handwaved the issue by saying that Scotty was momentarily confused.
"The only way to address the Scotty/Relics issue in Generations was not to have Scotty in the
movie at all. I wasn't willing to make that trade for the sake of a single
line that can easily be rationalized away by saying "Scotty was momentarily
confused." I still wouldn't do it."
AOL Chat with Ronald D. Moore
Which tallies with the explanation offered on the StarTrek.com website profile for Scott
Not until 2369 was it discovered he was the only survivor of the
ship's crash on the exterior of a Dyson Sphere, kept alive only as a
transporter beaming loop until, ironically, he was rescued by an away
team from the U.S.S. Enterprise-D — so disoriented that he thought
Kirk had come to rescue him. After trading barbs and quips with Chief
Engineer Geordi La Forge and helping to save that Enterprise, he
received a permanently "loaned" shuttlecraft, the Goddard, from
Captain Jean-Luc Picard and set off to roam the galaxy.
Scott doesn't think Kirk is dead
In the official novelisation of Generations, Guinan tearfully tells Chekov that Kirk has "gone to the other side".
Guinan was watching them go when a dizzying flash of memory overtook
her. Suddenly she was in the Enterprise-B sickbay almost a century
before, in a twi- light world between reality and the nexus, looking
up into the dark eyes of a man she later learned was Pavel Chekov and
saying, He's gone to the other side. Your friend, Jim.
Which was evidently interpreted by his friends as meaning that he wasn't dead, as explained in the EU Novel 'The Return'
“Personnel records?” Riker asked. “Anyone in particular?” Spock
hesitated. But he kept his attention focused on the screen. “James T.
Kirk… I never really accepted the fact I ... never really believed… that
he was dead.”
Riker saw how stiffly, almost formally, the ambassador sat in the
child-sized chair. It had been a difficult admission for him to make.
“You were not the only one,” Deanna Troi said softly.
Spock turned to regard the counsellor with an upraised eyebrow.
Deanna smiled. Riker felt bathed in her warmth, though it was directed
at Spock and not him. “Montgomery Scott said the same thing,” she told
the ambassador. “Believed as you believed.”
Riker remembered his conversations with the feisty old Scotsman.
Scott had been the chief engineer on the original Enterprise, where
Kirk and Spock had first served together. After Kirk’s first recorded
death, on the maiden flight of the Enterprise-B, Scott had led an
intensive search of the sector in which that ship had been damaged by
the mysterious energy ribbon known as the Nexus.
Decades later, when the chief engineer had been rescued from
transporter storage and had come aboard the Enterprise D, he had
explained the details of his search, how he had used experimental
sensors sensitive enough to detect individual molecules, let alone the
body of his captain.
In his personal quest, Scott had found the remains of other victims of
the force of the Nexus—shattered bodies blown clear of the ruptured
EI-Aurian ships. But he had not found all of the recorded EI-Aurian
dead. And, more importantly to him, he had been unable to find any
trace whatsoever of a human body.
“In fact, the first thing Mr. Scott said when he was recovered from
transporter storage,” Deanna explained to Spock, “was that he half
expected to hear that it was Kirk who had rescued him, taking the
first Enterprise out of mothballs just to come after his old friend.”
Star Trek: The Return