The vast majority of people (98%?) who are obese or overweight consume far too many calories (food and drink). However there are also conditions that can cause weight gain that are not related to overeating:
Cushings Syndrome: There is a condition where people have a high level of the hormone cortisol in their blood [source] - one of the symptoms of which can make people make massive weight gains. Cushings Syndrome is also know as Itsenko-Cushing syndrome, hyperadrenocorticism or hypercorticism. The symptoms (according to wikipedia) are "growth of fat pads along the collar bone and on the back of the neck (buffalo hump) and a round face often referred to as a "moon face." [source]
Cushings Syndrome can also be a side effect of long term usage of the use of Corticosteroids. "Corticosteroids are widely used to reduce inflammation and treat autoimmune conditions (conditions where the immune system malfunctions and attacks healthy tissue)." [source]
A much less common form is Endogenous Cushing’s Syndrome which occurs when a tumor releases too much cortisol in the body.
Hypothyroidism: Another cause of rapid weight gain is hypothyroidism, or an under active thyroid gland. The thyroid gland does not produce enough thyroid hormone (called thyroxine, or T4) [source]
Polycystic ovary syndrome (PCOS): where women have a large number of cysts in their ovaries. [source]
Certain medicines, including some corticosteroids and antidepressants, can also contribute to weight gain. Weight gain can also be a side effect of taking the contraceptive pill. [source]
Genes: A certain gene combination can mean that you more readily store fat cells than other people. [source]