Law 14 (penalty kicks) says:
"When a penalty kick is taken during the normal course of play, or time has
been extended at half-time or full time to allow a penalty kick to be taken or
retaken, a goal is awarded if, before passing between the goalposts and under
the crossbar:
• the ball touches either or both of the goalposts and/or the crossbar and/or
the goalkeeper
The referee decides when a penalty kick has been completed."
My brain hurt a bit reading that, but it seems to cover the situation where the ball hits the woodwork, bounces out, hits the keeper, and rebounds in - ie, the goal counts.
In the bit of the laws about penalty shootouts, it says:
"Unless otherwise stated, the relevant Laws of the Game and International
F.A. Board Decisions apply when kicks from the penalty mark are being
taken."
So - unless there's something somewhere else in the laws that I've missed (which is quite possible) - the referee got this one right. That seems fair to me because, even though the ball had moved forward, it was still the original momentum from the kick that took it over the line.
And, of course, because the keeper deserved it.