Electric shock - was I stupid, unlucky, or a combination of both?
The paranoid way to use a non contact voltage tester is:


Test that outlet shows as live
Flip breaker
test that outlet shows as dead
Test a different outlet that should still be live


The last step is what would have saved you a shock here - its to check that your tester didn't die while you were flipping the breaker, and that you haven't done anything silly like forgetting to turn it on.

Though if it were a loose connection you still could be very unlucky and have it pass all those tests with the outlet still live.