I've written about terminal lucidity before:
Some additional cases:
And here's a striking historical example, regarding Jonathan Swift, who suffered from senile dementia as he got older:
By 1732 he was noticing a serious deficient in short-term memory: "I often forget what I did yesterday, or what passed half an hour ago."
Around 1734 there is a marked change in Swift's correspondence. Depressed, lonely, and sick he was all too aware that his faculties were fading. The number of personal letters diminishes rapidly, partly because many friends were now dead, and partly because the strain of composing them was too great…Swift was finding it difficult even to write accurately, and when he read over his letters, he was appalled at the number of blunders.
By the fall of 1742, Swift's disability was so advanced that his food had to be cut up for him…At one stage an acute infection, orbital cellulitis, caused an eye to swell alarmingly, and the pain was so great that he had to be forcibly restrained from tearing at it. The episode did provoke a moment of lucidity, as Mrs. Whiteway reported: "What is more to be wondered at, the last day of his illness he knew me perfectly well, took me by the hand, called me by my name, and showed the same pleasure as usual in seeing me. I asked him if he would give me a dinner; he said 'to be sure, my old friend'…But alas! this pleasure to me was but for short duration, for the next day or two it was all over, and proved to be only pain that had roused him."
By now, according to Faulkner, Swift "forgot all his friends and domestics, could not call any of them by their names, nor for clothes food, or any necessities he wanted." Leo Damrosch, Jonathan Swift: His Life and His World (Yale, 2013), 460, 466