Mould is a fungus that thrives on wet surfaces. Mould spores are everywhere, including in your house. To grow and develop into mould, the spores need moisture. Mould grows well on carpets because they are great at trapping moisture.
Once a carpet gets wet (because of a ceiling leak, a basement flood, a plumbing problem, washing machine leak, high humidity or simply because you cleaned the carpet but did not dry it completely), moisture gets trapped in the dense fibres. Most carpets also have a backing that the weave is attached to. If the backing gets wet, or if moisture gets under the backing, the backing can trap the moisture under the carpet. Unless you actively work to dry a wet carpet using fans, a hot air drier or a dehumidifier, a wet carpet will stay wet. And it will not take long for a wet carpet to form mould.
There are many places in our houses where we do not look at the carpet regularly. There might be carpet in a closet or under a piece of heavy furniture that never gets moved. If the carpet in one of these locations gets wet, you might not notice it for quite a while, giving the mould plenty of time to grow and spread.