In my experience and opinion, this is done by travel-ball / elite / academy teams as an "order in the ranks" and intimidation ploy. If it's emulated by High School teams, it's because they have kids or a coach on the team who also play for academy programs, and/or are trying to play the intimidation card.
The "order in the ranks" comes out of youth players enrolled in an elite academy program, where Dad and Mom have ponied up a steep tuition fee and want to (nay, expect to) see results. So, the coaching staff drills discipline into them, which is all well and good... admirable, even... regarding every nuance of the game. They preach that preparation is key. How you stand and have your glove ready while out in the field, all the way to how you tar or tape your bat. One of the most visible signifiers of a team prepared (at least to Mom & Dad) is "timing up the (new) pitcher". I have actually witnessed a Dad scurry out of the stands to head behind the dugout, beckon over an (assistant) coach, and notify him of the (obvious... we're all standing around watching it) pitching change, and wondering why his son and teammates are not out of the dugout timing this kid up.
Looking prepared and in attention to the game is vital to Dad & Mom (and thus, the paid coaches) because it's what sets you apart from the unwashed, rabble rec-league teams where kids are having booger wars or farting on each other or pleading for snacks and Powerade through the rusty chain-link fence during a pitching change. So, to whip the troops into shape, and keep them focused on the game (and Mom & Dad happy!), the coach will trot all his players out of the dugout during a dead-ball situation and give them something to do. If they're on defense, you might see the end-of-the-bench kids hustle out to throw long-toss with the F9, or initiate a makeshift bullpen session in Foul Ball Territory. If on offense, this is where you get all bumpteen players out and doing something that demonstrates you're paying attention to the new pitcher and you'll be prepared when it's your at-bat.
Round-about age 14/15, it transitions from attention-demonstration to intimidation. At age 14/15, these kids have already seen enough pitches to become good hitters. Besides, their coaches, in these elite programs, have them conditioned to take pitches anyway. Instead, it's an intimidation ploy, to get in the head of this 16-year old pitcher who's being brought in after his teammate just got shellaqued by 4 straight doubles. As soon as the new F1 takes the ball, all 12 of you are out there, in front of the dugout, in your fancy uniforms, mohawks (gotta look like Bryce Harper), eye black (even though it's an overcast game) and swinging $200 composite bats. Oh yeah, pitcher, we've got you figured out.
We did the same thing in soccer and hockey. Heck, we still do it. We used to have a defenseman who would camp out at the blue line during the skate-arounds and bounce pucks and then slap shots in epic fashion at the goalie (which was often me). Was he really in need of practicing that? Nope. Was I in need of having to brace for and try and stop a tumbling rock while warming up? Nope. This was just to show off to the other team what he could do.