IMO it's clearly a mechanism for batters to make sure they are composed and ready for each pitch. By now it's become simply a crutch, and/or evidence to a coach who has been on his case that his head is in the game. If the rules forbade it, they would all find a different mechanism instead (popping oneself on top of the helmet, for instance), and the game would move faster with no loss of focus by the batters. Ditto for pitchers who have developed similar routines between pitches, pawing at the mound and so forth. It's gotten out of hand on both sides, baseball has the ability to add a rule when things get out of hand, no big deal.