One of the most common reasons why pillows can turn yellow is body sweat. Your body sweats to maintain homeostasis in regard to temperature. Even when you're sleeping your body continues to sweat to keep your body at an optimal temperature. Depending on the type of fabric your pillowcase is made from, sweat can seep through the fabric. As the sweat dries, it can leave a yellow stain on the pillow.
Exposing your white pillows to direct sunlight for extended periods of time can also turn them yellow. Manufactured white fabrics tend to have an extra coating of fluorescent whitening agents to give fabric a much truer white look. As sun hits this layer of treatment, the materials of the whitening agent can begin to break down. This exposes the true color of the fabric beneath, which looks yellow in comparison to the white coating.
Another common extra coating used on pillows to give them a bright white color is an optical brightener. Like fluorescent whitening agents, these coatings can break down in sunlight but can also break down on their own over time. This is why many older pillows or heirloom pillows tend to yellow, even after washing.
Oxidation can also turn a pillow yellow over time. Oxidation occurs as the fabric fibers are exposed to oxygen. This can naturally cause the pillow fibers to slowly turn gray, yellow or a mixture of both over time.