Weight gain is a result of eating more calories than you burn on a regular basis, not when you eat those calories.[1,2] Due to their preference or schedule, there are many people who eat later in the evening, before bed or even wake up in the middle of the night to take in calories. If one gained weight doing this, it was due to excess calorie intake, not the timing.
The body does not have an enzyme with a watch that after 7 p.m. preferentially stores items, especially carbohydrates, as fat. We all have a certain number of calories that we can consume without gaining weight. As long as that number is not exceeded, weight gain will not occur. Imagine this scenario: it has been established that you burn 2750 calories in a 24 hour period. You had a busy day and since your 350 calorie breakfast, you have not had the opportunity to eat. You get home late after a long day of meetings and you are ravenous. At 9 pm you eat an enormous 1500 calorie meal. Added to the 350 calorie breakfast this brings your daily total to 1850 calories. After your late meal you are exhausted and promptly go to bed. Will you gain weight? Let's look at the math: your daily energy expenditure is 2750 calories and you ate 1850 calories. This leaves a deficit of 900 calories. The body cannot make/retain body fat from nothing. In this example, considerably more calories were used during the day than were eaten, leading to a reduction in fat stores when all was said and done. The goal is to figure out how many calories you can have during the day to lose or maintain weight and distribute those calories/foods in a manner that makes you feel your best, including preventing hunger. If you do this regularly, then you will accomplish your goal no matter what time you eat.
References
1 Hill JO, Wyatt HR, Melanson EL. Genetic and environmental contributions to obesity. Med Clin North Am 2000; 84: 333–46
2 Bes-Rastrollo M, van Dam RM, Martinez-Gonzalez MA, Li TY, Sampson LL, Hu FB. Prospective study of dietary energy density and weight gain in women. Am J Clin Nutr. 2008 Sep;88(3):769-77.