How does a tree trunk sprout and grow after being cut?
This is basically the same that happens after pruning and involves a basic hormonal regulation mechanism in the plants.

What happens is that the cut piece of the wood forms a new meristem which allows the growth of new organs. What’s important is that there is no other growth happening nearby, since that would hormonally inhibit any further growth. This is why such growths happen once you’ve cut the wood, not before (on the healthy stem). This inhibitory effect is known as apical dominance, which has now been disabled.

As to where the energy and water comes from, to some extent it is stored within the branches themselves. That’s why you need to dry them before being able to use them in a fire. However, this growth is pretty limited. Further water is probably collected by condensation of water vapour in the air.