Fastidiousness. Being considerate to others.
As with many cultural peculiarities/quirks/anomalies, there is usually not one single explanation. But IMHO the single biggest explanation is a combination of being fastidious and considerate to others.
To walk while one eats or drinks is to elevate the risk of food/drink spillage. And doing any such thing would be truly awful because of the awful mess it would create and the awful inconvenience it would cause others.
The chosen answer suggests that if one buys food from a roadside stall, it is OK to stand there and eat it. This presumably shows adequate "respect for food".
But in that case, why is it not OK if I go to Lawson's, buy an onigiri, and eat it there? Wouldn't I be showing at least as much "respect for food" as in the above scenario?
The difference I think is that in the former case, it is customary and fully expected that the stall proprietors bear the burden of cleaning up after any mess that you may leave behind. Whereas in the case of Lawson's, it would be a terrible inconvenience that you'd be causing the already-busy employees were you to spill any food.
P.S. The chosen answer also claims that the Japanese "respect for food" is reflected in the way in which they eat every last morsel of their food. This has less to do with "respect for food" than with the historical experiences with deprivation.
The Japanese proverb 粒粒辛苦 ("every grain hard work") which every Japanese schoolchild is taught, comes directly from the Tang Chinese poem which every Chinese schoolchild is taught (谁知盘中餐,粒粒皆辛苦).
The point is NOT about any semi-mystical "respect for food". Instead it is simply about avoiding the waste of any food or any resources in general about not wasting food or resources in general (mottainai in Japan).
Thus, the Chinese, like the Japanese, eat every last morsel of food because in both cultures, one avoids wasting food or any resources. However, the Chinese, unlike the Japanese, are perfectly fine with eating/drinking while walking, because the Chinese are less fastidious/considerate than the Japanese and are less bothered by a bit of filth and disorder (as is evident once one spends a bit of time in each country).
P.P.S. hippietrail suggests in a comment that "people in Asian countries don't eat while walking generally". This is false. It is Japan and solely Japan that is anomalous in this regard. (Note that of course historically, pretty much EVERYWHERE in the world, people generally never ate while walking. It is mostly in the modern busy era that people do this. And only in Japan is there an unwritten prohibition against doing so.)