It's especially common in panther chameleons, I believe, especially younger ones.
It could be a territorial thing, or a sensory "checking out my environment" thing. But I think I may have also read that in the wild some species may do this because there is mineral-rich "dust" that ends up on branches blown in from the wind and that it's a subconscious way to get more nutrients. In captivity I doubt it serves much of a purpose
Various chameleon species are known to touch branches with the tip of their tongues (which are actually forked much like monitors and snakes), in what is often referred to as a tongue touch behavior. It hasn't been explicitly proven but it is likely that this behavior is actually an effort to pick up chemical ques in an effort to taste a new territory, possibly for the presence of other chameleons. It is speculated that males will often rub their vent or the secretions from their temporal gland on branches, possibly to mark territory. These chemical ques may then be transferred and deciphered by the Jacobson's Organ.