I have to believe this self doubt didn't just suddenly creep up on her in the moment. She must have had some lingering doubts leading up to the trials about whether or not she could go through the pressure of another Olympics. That being the case (again, I'm just speculating) the right thing would have been to step aside and let someone else go.
I can only imagine the pressure from sponsors for her to deliver and her not wanting to let them down (or lose her meal ticket) would have made a decision to step aside before the Olympics incredibly hard, but it would have been the right time to do it.