Since the issue is not only with food that you can spill but also with drinking coke (even if you buy it from a vending machine, you are not supposed to drink it while you walk), which is pretty much impossible to spill, this is not a hygiene issue.
The topic is much more about the respect for food at large. When Japanese people start eating, they put the hands together in a praying gesture and say "Itadakimasu", wich means "I humbly receive". People are also supposed to finish their food, even down to the last rice corn. There is another phrase to thank the cook once you are finished. Several other cultural details exist that underline this deep respect for food.
When you are eating while walking, you are taking food too casually, and forget to pay respect to the people who grew/made it and the souls of the organisms who perished in the process. You are supposed to cherish your food, which is taken to comical extremes in the "Ramen Scene" of the movie "Tampopo", which is a comedy only about food in Japan.
There are a lot of restaurants that serve food on the street, but you are supposed to eat it right there, on the spot, often under a canopy or umbrella, instead of walking away with it. Probably the only exception is ice cream. It is very possible that it is exempt because of western influence.