The culprit behind this struggle is a rheological phenomenon called thixotropy. First, a word about rheology; rheology is a sub discipline of mechanics, specifically the study of the properties of materials which determine their response to mechanical force, as well as the deformation and flow of matter.
The word rheology is derived from the Greek rheos, meaning "flowing stream, or current." Rheology straddles both main branches of mechanics: solid mechanics and fluid mechanics.
The term thixotropy, like many of it's fellows in scientific nomenclature, derives from Greek as well: thixis "touching" and trope "turning." In a nutshell, thixotropy is a property of certain materials wherein they behave as fluids when agitated but are semi-solid or solid when undisturbed.
In more technical terms, fluids with a high viscosity, or resistance to flow, are thixotropic if they exhibit time-dependent shear thinning. That is, when subject to shear stress over a period of time (for example the agonizing few seconds of vigorous ketchup bottle shaking) these materials will become less viscous. Then, when undisturbed, they will return to the equilibrium of their original viscous state within a fixed amount of time.
Common items that are thixotropic include yogurt, printer ink toner, whipped cream, and many cosmetic gels and colloidal creams.
There are even some fluids that are anti-thixotropic, wherein shear stress applied over time results in an increase in viscosity, or even solidification. This property is referred to as rheopecty.
Some very clever folks at MIT have apparently devised a solution to this rather annoying mechanical property called LiquiGlide, a substance that could be applied to the inside of containers such as ketchup bottles that would make the contents easily pourable: