It usually refers to making a mistake, and later realizing that you could have done things differently. Hence, looking back at the past, the “hindsight” you can see so clearly—“20/20” (refers to perfect vision) what could have been better.
Like emilyrose said, it’s about being able to see clearly your mistakes in the past. It’s also about justifying your mistakes in the past, since the implication is that you could only realize they were mistakes retrospectively.
It isn’t just mistakes you can see clearly in the past, it’s everything.
If only I’d known about the economic meltdown, I could have protected my savings. If only I’d known that the Phillies would win it all, I could have made some big sure bets.