I've found that as well, and unfortunately, my answer has to be "not always as gracefully as I'd like." It seems that people are often very happy to give and offer support and understanding, but when we go through rough times, we really do find out who's truly there because they love us and who's just along for the ride.
As for the why, I think that we have varying levels of connection in our different relationships. The trouble and disappointment comes when we expect a greater level of attachment and loyalty from someone than they believe they owe us. This difference often becomes apparent when we lean on them for support during a time of need and they pull a shoulder away. It's painful, but it can be a very harsh and meaningful lesson.
When people are quick to judge others, I have to assume that they're covering up for something in their own psychological closet. The issue is not with you, it's with them. You're responsible for your own choices and actions. Those who truly care about you may not always agree with those choices, but they will always respect your right to make them, and even your right to fail now and then. They will not love you any less for it, or judge you when you're down. Anyone who does probably didn't really love you in the first place, or at least they have some issues with showing it.
There might not be anything you can do about the other person's judgment, but you can learn from it as I've had to do plenty of times. There are people I'm still friends with, but I know not to trust them with my struggles or the intimate details of my success, because they proved themselves judgmental and unsupportive when I needed it most. I view that as sacred knowledge now, though at the time all I could see was the pain.
I hope sincerely that you have others who won't judge you and can offer the support you need in tough times as well. Everyone deserves that. All the best to you.