Why do they happen?

That is a very good question.  There are several… actually quite a few reasons that spots and stains re-appear, however, we’ll only discuss the main ones for now. 

Most everyone has experienced the reappearing spot and stain syndrome.  The main reason that spots or stains re-appear is due to wicking action.  What that means is that the residue from whatever caused the original spot has re-wicked its way back to the surface of the carpet’s fibers during the drying process.  Here’s how it happens:  First the carpeting receives a spot due to any number of reasons; soda spill, oil from shoes, dogs, feet, urine, and even a spill from a glass of water will cause a spot / stain.  The spot / stain causing element gradually or quickly (spills) works its way into the carpet’s primary and secondary backing, and then of course the cushion or padding.  Second, the homeowner applies a cleaning chemical, water, or some other form of attempt to remove the contamination, which usually carries the contamination deeper into the backing and cushion.  Third,  the stain appears to have disappeared, and the several days or weeks later, the spot or stain reappears.  It reappeared because as it dried, some of the spot causing molecules resurfaced at the tips of the fibers due to wicking action.  Wicking action is the result of the surface tension of water molecules.  Generally, what that means is that as evaporation is taking place, the water molecules “dry” (evaporate) as they travel upwards.  Through the process known as surface tension, each water molecule is “linked”, and subsequently pulls the next molecule upwards with it.  As the water molecules pull each other upwards,  they also attach to the molecules of the spot causing problem, and the soap which was used to clean the spot causing problem.  As a result, the spot causing problem, and now the soapy residue is back at the tips of the carpet’s fibers.  In addition, the spot or stain has spread out and become larger than it was originally.  Carpet cleaners then attempt to remove the spot or stain by re-wetting the area to gain fluidity.  By now, however, the contamination is in the padding. Without actually pulling the carpeting and subsequently cleaning the backing, there is no way to eradicate the contamination completely.  We can, however, thoroughly rinse the affected areas and this time we must apply a cleaning solution which will first neutralize the cleaning chemical which was used by the homeowner, and secondly, neutralize the spot or stain causing agent.  The more we rinse and extract, the more of the problem we can remove to a point.  Eventually, the contamination which was in the backing of the carpeting or padding will re-wick its way to the surface once again.  The most important tool in preventing spots and stains is quick action by the homeowner.

 
You’ll notice that I refer to spots and stains.  Spots are particles which have merely attached to the carpet’s fibers, where as stains are actual changes to the carpet’s color.  Soda, juice, coffee, mustard, oils, and anything acidic are examples of stains.  Stains can usually be removed (almost never completely) to the point which makes them acceptable and tolerable.   
Remember, this is just one of many possibilities as to why spots and stains reappear.   There are numerous other causes and subsequent methods for removal.