There's a medical syndrome called Prader Willi Syndrome, and it's a very serious disease. There can be some developmental delays and intellectual disabilities, but one of the most compelling parts of the syndrome is a fascination with food, and an insatiable desire to eat. It can be a really difficult disability to manage. My friend's son is affected by it.
Anyway, that's obviously not what your son has, but if you look up the syndrome online, specifically "kitchen locks" you will see tons of helpful ideas about what families have to do to lock up their food and prevent access to their appliances at night. Lots of creative ideas. My friend does not chain her fridge, but she has strategically placed locks and other things to prevent access to food except at specific meal times according to her son's doctor's instructions and plan. I have another friend with a severely mentally disabled daughter who is able to access the appliances but does not have the ability to work in the kitchen safely, and she used some of the Prader Willi suggestions as well, just to be able to sleep at night or take a phone call or shower and know that her daughter wasn't lighting something on fire or drinking the entire gallon of milk from the fridge.
You also might consult a nutritionist (a certified one, ask your doctor for a recommendation). Some medications cause night-time hunger. And nutritionists have ideas about limiting access to foods.
Another idea: where are you buying the melatonin from? My daughter suffers from Delayed Sleep Phase Syndrome and has the narcolepsy gene and another sleep disorder, and requires melatonin and other medications to sleep. She has been through multiple sleep trials of all kinds. One prominent doctor (president of a national sleep disorders board of certified sleep specialists) taught us about melatonin.
First, it's not regulated or approved by the FDA. If the bottle says FDA approved, don't buy it. That little blurb on the bottle tells you the company is trying to pull a fast one on you, or lying outright. Second, a pharmacological study (not by people interested in selling things, but by a group of researchers) was done on a lot of melatonin brands (CVS, Costco, Walgreens, mail-order sources, health food stores, etc). 99% of them had a problem. Some contained way too much melatonin, some contained very little, some contained poor quality melatonin from questionable sources, some contained harmless additives like sugar and not much melatonin, and some pills from the same bottle contained vastly varying amounts of melatonin. The doctor told us to only order melatonin from a company called Life Extension Foundation (an no, I don't sell it, nobody does, and I'm not affiliated with it, nor was the doctor). But their melatonin was the only one that passed the test: consistent from pill to pill, containing the amount specified, pure and safe and reliable. Their website is easy to find and use. And it's about the same price as other melatonins.
Also, make sure he takes the melatonin about 2 hours before bed. There's a long-lasting slow release kind, and an instant release kind. My daughter takes both.