The current world number one from Malaysia dropped to his haunches at 19-16 down and then tried to recover.
But he had to retire from the match at 20-17 -- leaving Lin, who is world and Olympic champion, to take the title 16-21, 21-13, 20-17.
"It would appear that he suffered some cramps and he has subsequently been taken to hospital," said Gayle Alleyne, communications manager for badminton's world body the BWF at a press conference after the match.
Lin, 29, known as "Super Dan", was making his comeback at the tournament with a controversial wildcard place after a year on the sidelines to spend time with his family.
More From This Section
The two badminton legends put on a brilliant display in the first set in front of a packed Tianhe gymnasium in the southern Chinese city of Guangzhou.
"He got this cramp out there and it reminded me of my training -- when you have that, you cannot move at all. From that moment we were not opponents any more. I really wanted to help and I went over to ask if he was OK. He didn't want to give up."
Lin's victory sealed a day in which China won only two of a possible four medals after sweeping all the titles at the last two world championships and at the London Olympics.