Evolution dictates how a certain species will evolve and change over time and many factors govern the evolution including, habitat, diet, predators, etc. The body shape, size and various other characteristics will develop over time to suit the conditions in which a particular organism has to survive and their population to grow.
In case of hummingbirds, the beak shape and length is governed by the food they eat. Their long, slender beaks allow them to sip nectar from flowers. If instead of flower nectar, their main diet was different, say fish, then their beaks would have been deep pocketed to capture fishes, just like pelicans. Or, it would have been sharp like that of woodpecker, if their main food was worms in the tree trunks.
The hummingbird's diet would greatly influence the beak length and shape. For example, if a hummingbird's food is flower, they would have longer beaks so that it would fit into the flower and will be able to suck the nectar out of it. In contrast, if a hummingbird preys on worms, they would have shorter beaks so that they would be able to peck on the ground.