Why do egg yolks curdle?
In a word: Science! The yolk of an egg contains a large number of complex proteins, which are large molecules composed of chains of amino acids.  The specific combinations and ordering of those amino acids cause the proteins to fold up on themselves into complex structures, which in turn determine the protein's function.

The bonds which interact between amino acids and fold the protein in a specific way are fairly delicate, and they can be "denatured" or disrupted by the application of heat, salt, or acid, which changes the shape of the protein.  The bonds can also reconnect to other, different bonds when the protein is in its new shape.  So, when you heat an egg yolk, the proteins eventually change shape and bind to each other in a specific way that causes the physical changes we refer to as "curdling".  Here's a neat animation of the process.

This can be avoided when the yolks are heated gently because it takes a certain amount of heat to completely denature the proteins, and it takes a number of unfolded proteins interacting to bind into a new "curdled" configuration.  When you heat gently, you're giving the heat enough time to dissipate throughout the food, so that it doesn't exceed that temperature in any given spot and there aren't lots of fully denatured proteins all in the same place.  The proteins may still be changing shape, but they haven't reached the shape or concentration where they can bind together and curdle.  Which is good, because when they do bind together, those bonds are stronger than the bonds that originally folded the proteins.  At that point they're permanently curdled and no amount of cooling will un-bind them and allow the proteins to re-fold on their own. (EDIT: ironically, I stumbled on this article today which describes how some scientists have managed to do just that with certain egg enzymes. Weird!)

The final configuration can also be mediated by other proteins, sugars, etc. in the food.  For example, in scrambled eggs the proteins in the whites and yolks combined set differently than either of them do separately.  The cooking process can also be done gradually enough to produce a smooth texture even if the proteins are completely denatured.  For example, in hollandaise sauce egg yolks work together with liquid butter to form a smooth emulsion; even though many of the yolk proteins may be denatured, they can't fully set into a curdled matrix because the butter proteins, fats, etc. are also present.

A bit more detail on how to prevent curdling in specific culinary applications can be found in this related answer.