This phrase is often used sarcastically to express doubt about the likelihood of an event. You becoming an astronaut? Sure, when pigs might fly.
Pro Tip 2/3
Cultural Improbability
This idiom exists in different forms in various cultures, but it always implies an impossibility. He'll volunteer to wash the dishes, when pigs might fly!
Pro Tip 3/3
Informal Humor
Use this phrase in casual settings for a humorous effect, not in formal situations. Me, win the lottery? Ha, when pigs might fly!