Many factors. There are several reasons for weight gain. It can be as simple as eating too many calories, or eating the wrong calories, or not getting enough exercise. You will gain weight when you take in more calories than your body burns each day. There are also medical conditions and hormone imbalances which cause weight gain, and medications with side effects of weight gain.
Excess food. The short answer is, when caloric intake exceeds caloric expenditure. In other words, eating more food than is needed. Rarely, very rarely, it may be due to metabolic defects, .
Food additives. If you look at all the extra ingredients that food manufacturers put in our processed food that would not be there if you made the same from scratch. Hydrogenated oils, high fructose corn syrup, "spices" (when other spices are listed specifically), " natural flavor", various dyes, among other things that are not good for our physiology. I truly that that less processed food is better.