Some people are hungry a lot. For a variety of reasons. For example, the choice of previous foods they've eaten can result in increased hunger. As can metabolism. And activity level. I suspect microbiome as well, although I don't recall specifically reading anything about that. Depending on the person, stress may increase hunger or decrease it. Depression can have the same impact of either increasing or decreasing hunger. Some of the people experiencing increased hunger may gain weight, some won't.
Different people also get different levels of pleasure from eating. Some very little, some very much. The effects on serotonin, dopamine, and endorphins differs from person to person. I know I saw one study once where they found that the pleasure centers of the brain lit up much more than average in overweight people when they merely thought about their favorite foods, and much less than average in people who had been thin their entire lives.
I think you're correct in that many people eat out of habit. They also eat from boredom. Some people begin to feel hungry merely at the mention of food.
So I don't think it's as simple as telling people to only eat when they are hungry. Although that's a good rule of thumb, you may need to also address some of the other factors (like food choice, depression, etc.) if you want a given individual to remain at a healthy weight.