Ahh, wicking. This is when stains are deep enough into the carpet fibers that a steam cleaning will appear to have cleaned it, but after drying, the stain essentially “travels” back up the fibers and magically reappears. Most often, this is because the stain has penetrated all the way down through the carpet and into the pad. There’s not a ton you can do about these stains short of replacing the carpet and the pad.
To keep new ones from happening, deal with new stains as quickly as possible. For some people (like me), investing in an upright carpet steamer (mine was less that $200 on Amazon) is worth it to treat stains before they settle. If you go that route, look for a steamer with a “rinse” setting, or make sure to go over carpets with plain water and no detergent in the steamer after cleaning. The soap residue can attract dirt, making new stains.
I Googled to make sure I was calling everything by the right name, and this guy seems to have good, well-explained reasons for reappearing stains.