There are numerous ways that water can end up on carpet and cause water staining. Rain through open windows, snow and water tracked in, burst pipes or leaky radiators, flooding, and probably the most common way, spills.
Water stains are facilitated by slow drying which allows materials to dissolve out of the carpets backing and wick up, or evaporate up, into the top of the carpet fibers. This causes a brown discoloration which is usually referred to as a water stain.
Water stains can be very difficult to remove, even for professionals. A typical approach is to rinse out the stain, and then work to put the Ph of the carpet fibers back into balance, or to neutral (which is 7 out of a scale of 1 to 14). Browning agents, stronger versions of house hold vinegar (which might work in some cases), that have a Ph of 5-6 are applied to the water stain and agitated to remove or reduce the appearance of the water stain.
When carpets becomes overly wet with spillage, etc., water stains can be prevented from developing by faster drying. So, soak up as water as possible with clean white toweling, then help get the effected area dry with household fans or hair dryers on warm air.