It looks like it *might* be from The Rise of Darkrai movie, just after Pikachu shocks Ash to wake him up from a Dark Void nightmare that Darkrai put him under...I think he gets shocked again for squeezing too hard right after the gif ends.
I could be wrong, but that's what it reminds me of.
I can recognize scenes from the Rise of Darkrai anywhere. The GIF has that classic heightened animation quality the movies had over the main series anime, and I do believe this is when Ash wakes up from his Dark Void nightmare. Definitely an awesome movie :)