When a whiplash occurs, what causes the pain afterward: the forward movement of the head or the snap back?

Both. Whiplash has two separate phases very close to what you've described. In the first phase, the person's head actually goes backward into extension. The head and neck then return to the neutral, upright position before going forward and snapping back again. It happens so quickly the person isn't really aware of all the distinct movements.

Strain to the joints and ligaments occurs at different points in this movement. The neck ligaments are strained the most during that first backward phase returning to neutral. Then the joints are pressed together and slide forward and back. Any of these motions can go beyond where the joint is normally capable of going.