As in all young mammals, a baby elephant has a sucking reflex, it may suck its trunk for comfort, just as a human baby would suck its thumb.
Baby elephants suck their trunks just like baby humans suck their thumbs. And they do it for the same reason, comfort. Just like human newborns, elephant calves are born with a strong sucking reflex. This helps them instinctively know what to do when they are near their mother's breast.
Therefore, sucking equals comfort. When a baby elephant is not nursing, it might suck its trunk just like a human baby might suck a pacifier.
Aside from the comfort it provides, trunk sucking helps an elephant calf learn how to use and control this lengthy appendage. With more than 50,000 individual muscles in the trunk, you can imagine how complicated it is to get it to do what you want it to do at any given time. Sucking on the trunk helps a young elephant learn how to control and manipulate the muscles in the trunk so that it can fine-tune its use.
Elephants also suck their trunks as a means of advanced "smelling." They can taste the pheromones of other elephants by touching their trunks to urine or feces and then popping the trunk in their mouths to get a closer whiff.
While trunk sucking is primarily a mannerism found in young elephants, older elephants, even mature bulls, have been seen sucking their trunks when they are nervous or upset.