Why do the moths come back after I threw the food out?
Usually because the larvae had already left the package. They crawl out to pupate in a sheltered spot, which is the shelf corner, the runner, a hinge or the gap behind a shelf. Removing the food leaves those behind, and they emerge days or weeks later into a cabinet that looks clean.
This single mechanism explains most of the frustration with pantry moths. A household finds the bag, bins it, cleans the shelf surface, and two weeks later there are moths again. Nothing was done wrong except that the surfaces that matter were not the flat ones.
So the clean-out concentrates on the edges: shelf corners, the underside of shelves, runners, hinges, the seam where a shelf meets the wall, and the inside rims of lids. It is a slow ten minutes per cabinet and it is the difference between a solved problem and a repeated one.
Where is the source most often found?
Rarely in the package you suspected. Forgotten bags at the back of a shelf, pet food, birdseed, bulk grain, dried fruit, nuts, and dried decorative material are the usual finds, and sometimes it came in already infested from wherever it was bought.
Because these insects can be in a package before it reaches a kitchen, a spotless cabinet is no protection. That also means the moths appearing now may have nothing to do with how anything has been stored, which is worth knowing before anyone starts apportioning blame in a household.
Non-food sources are the ones that defeat people. Dried arrangements, a long-standing spill under a unit, and material cached in a void by rodents can all support them. When a thorough food search finds nothing, those are the places the visit moves to next.
Is treatment even necessary here?
Often it is a small part of the job. The search and the clean-out do most of the work, and where treatment is used it goes into the cracks and crevices of an empty cabinet, to label, never on food or on a surface food sits on. Sometimes the right answer is no treatment in the cabinets at all.
This is one of the few pest problems where a careful hour and a bin bag beat an application. A technician who turns up and sprays a pantry without going through the packages has not done the job, and the moths will be back in two weeks for the reason described above.
Where treatment helps, it is as a backstop against pupae in places a cloth cannot reach, applied in an empty cabinet with a stated time before restocking. You are told what went where, which matters more in a food cabinet than anywhere else in a house.
How should food be stored afterwards?
In hard containers with proper seals rather than in the packets they arrived in. That does two things: it stops an infested package spreading to its neighbors, and it makes the next problem visible immediately instead of in six weeks. It also makes any later inspection far quicker.
Glass and rigid plastic with a seal are what work; a clipped bag or a folded packet is not a barrier. Bulk purchases of grain, flour, pet food and birdseed are worth decanting on arrival, because those are the packages that most often turn out to be the source.
It is also worth having a habit of using older stock first and periodically looking at the back of the shelf, which is where the forgotten bag always is. None of this is exciting advice, and it is the reason most households that have had pantry moths once do not have them twice.