I don't know exactly what causes nighttime snacking, but I used to do it all the time. It was like, I could eat just perfectly fine all day long, and then as soon as nighttime hit, BAM! I was raiding the fridge or hitting up McDonalds.
You can get past it though. I know it's hard, but resist the urge. After a few days, it will be easy and become a habit. Drink plenty of water. If you must, snack on some celery or cucumbers. Chew gum. Go for a walk or bike ride to take your mind off of eating. Whenever I get a SUPER serious urge to eat when I shouldn't, I exercise. Takes my mind off of it, and instead of doing something horrible for my diet like binging, I'm doing something very productive