From the Super Mario Wiki
At first, the Vending Machines only sells Coal as visiting the place is useless before doing Locomotionless.
When the player goes to the Train Station and takes the Quest, the Vending Machines come in handy. The Shy Guy that works on the Train Station mentions that he needs Coal to run the Train. When the player buys Coal from the Vending Machines, he or she must give the item to the Shy Guy, which will result in getting a Gaddget, the Cake Maker.
Mrs. Shroomlock mentions that the Vending Machines actually sell the item, coal, when the player takes the quest.