All it really comes down to is the fact that, if you consume more calories than you burn, you're gonna gain weight -- it doesn't really matter when those calories are consumed. One thing helping to maintain the late night weight gain illusion, according to Picture Fit, is that when people snack before bed, it tends to be on less-healthy foods that would lead to weight gain regardless of the time they're consumed.
Now, does this mean you should feel free to indulge your sugary proclivities before lights-out? Probably not: while they might not lead to undue weight gain, some foods can still disrupt your sleep cycle if they're eaten before going to bed.
Bottom line is, exercise common sense when picking your midnight snack. Failing that, maybe just exercise.