Put simply, obesity is a result of an imbalance of calories consumed and energy expended over time. Evolution can take thousands of years, so our bodies are not yet adapted to deal with the quite sudden changes to our lifestyle that have happened over the past century.
Modern food processing has also meant we have an abundant supply of calorie rich foods at our fingertips year round, where only two or three generations back in time we ate what we produced, and were not exposed to the high sugar and high fat ready-made foods that are available today.
However, there are more factors that can cause obesity than taking in more calories than we can burn. Some people have a genetic predisposition to gaining weight, so would easily put on weight while eating the same diet as a naturally skinny person who never seems to gain any weight.