From what I understood, Riki's narcolepsy isn't true narcolepsy but is rather a symbol of his weakness. After he and Rin escape the first time, he creates a world where he can truly cope with the sadness and loss he faces with the death of his parents ("the encounter is more important than the loss" scene). And because of the dynamics of the "fake world time reset" stuff we know with Kyousuke, he reset back to the scene of the crash, this time with his narcolepsy gone.
So yeah, Key magic.