Avocado pits contain a milky, bitter liquid, which turns red upon contact with oxygen in the air. The reason is the high concentration of tannin in avocados. Only the avocado pit will turn red, and usually only after its surface has been broken or it has become very overripe or decayed.
TL;DR (Too Long; Didn't Read)
Avocado pits contain a high level of tannin which makes them turn red. Tannin is also responsible for the bitter taste of avocados when cooked.
Tannin Causes Astringency
Tannin is not one particular compound, but rather a whole class of biomolecules. It gets its name from the historical use of oak tannins used for the tanning of animal hides into leather. Its astringency causes the dry, puckering sensation you experience upon drinking a dry red wine or biting into an unripe fruit. Tannin is found in nearly all families of plants. In trees, dark, hard woods have higher concentrations than trees with lighter or softer wood. Most nuts, berries, and many herbs also contain tannin and it is an important component of the flavor of many fruits.
Tannin Content of Avocado
Both the flesh and seed of an avocado contain tannins, but only the seed has a high enough concentration to create a red color. The presence of tannin in the flesh of the fruit explains why avocado becomes bitter tasting when cooked. Avocado seeds contain about 13.6 percent tannin.
Tannin Can Be Toxic
Tannin is somewhat toxic to many ruminant animals such as goats or sheep. Some highly sensitive humans also experience indigestion upon consuming high amounts of tannin. In very high amounts, tannin may reduce the digestive system's ability to absorb certain dietary minerals such as iron. Tannin chemically bonds to iron and other metals, especially those contained in foods eaten at the same time as the tannin-containing food, causing the metal-tannin complex to pass through the body undigested. This process is called metal chelation. It is usually not an issue, however since the bitterness of tannin makes it unpleasant to eat enough to make it harmful.
Used for More Than Tanning
Historically, the milky, tannin-rich liquid from avocado pits was used as an ink. Many surviving documents from the Spanish conquest of Central America and South America were written with avocado-based ink, which is usually dark red in color.