Jeremy’s dad is startled to see flying pigs. But then he finds out that Jeremy cleaned his bathroom without being threatened. So he reasons: for Jeremy to do this, pigs will have to fly; Jeremy has done this; therefore, pigs must be flying. The flying pigs are explained.
When pigs fly is a formula conveying ‘never’, given that pigs don’t fly: if you say that X will happen when pigs fly, you’re saying that pigs flying is a precondition for X happening, so if that precondition can’t ever be satisfied, then X won’t ever happen. Any precondition that the speaker believes won’t ever happen could serve in this reasoning, but pigs flying has been conventionalized for this purpose.