Goldfish may leap out of their tanks if the water is too warm, or if it is not at a proper acidic level. Irritants building up in a tank that has not been cleaned recently, external parasites, and lack of oxygen in the water from waste gas build-up are also common causes for this mystifying behavior.
Goldfish prefer an environment between 65 and 75 F. When temperatures rise above 75, they are triggered to spawn. A fish eager to breed will become very active, swimming rapidly and even leaping from its bowl.
Acidic water and alkaline water both irritate the sensitive skin of goldfish, causing them to swim erratically and leap to escape the pain. Proper pH in a goldfish bowl should be between 5 and 8.5. Common tap water is pH 7, but waste from the fish can make the water acidic. This is why switching to a different brand of filter can cause goldfish to suddenly exhibit leaping behaviors: a filter that doesn't work the way a fish is used to, or which is improperly installed, can make the water irritate the fish.
Fish that are infected with skin parasites will attempt to rub them off on foliage, rocks, the sides of the tank and anything else they can get in contact with against their skin. Sometimes this vigorous rubbing results in accidental leaps.
Deoxygenated water will result in leaping and gasping. Goldfish of course cannot breathe air, but water close to the surface contains more oxygen than deeper water.