A lot of people believe that eating late in the day will make you gain more weight than eating earlier. This is partially true. At the end of the day it is the total amount of calories you eat that dictates whether or not you'll gain weight.
The problem is that while we're sleeping the body's metabolism slows and with that its need for calories decreases too. If you eat 500 calories right before going to sleep, its more likely that a large portion of them will be stored as fat.
On the other hand, if you eat 500 calories at lunch time, you're much more likely burn those calories by doing work, going to the gym and walking around than you would be at nighttime.
We still burn calories during sleep. Your body does most of the repair and restoration during sleep and it does need energy for this. You shouldn't avoid late meals but instead of eating large ones go for a midnight snack.