Japan has so many, but why? You can cite love of gadgets, etc. but I want something more general. After all, Japanese retailing has a very high ratio of small stores serving a local clientele; surely Japanese vending machines are another example — albeit an extreme one — of that more general trend.
First we must look to the shortage of storage space in homes. I suspect few Japanese want to buy big piles of stuff at Costco. So buy smaller "portions" and in the meantime the inventories are stored in the vending machines, where they are more or less at your disposal.
Cars of course are another means of storage and also a way to transport goods in bulk (NB: you carless people have a hard time pigging out at the public library, you poor souls). But most Tokyo residents don’t use cars so again they buy goods in smaller numbers which again points us to the vending machine. Buy one disgusting sweet fizzy juice, drink it on the spot, and walk to your nearest vending machine when you need another one.
You’ll notice that vending machines are especially popular for canned and bottled liquids, where the ratio of storage and carry costs to per unit value is relatively high.
This article associates vending machines with the nomadic lifestyle.