The trick is to throw the bat at the target repeatedly with Z, then follow with a fully charged swing.
Sonic's speed is the advantage here. He covers ground faster than most of the roster, so you can reach the sandbag and line up the swing with more time to spare. That extra margin is what turns a decent score into a good one.
The demo that plays before the contest is genuinely instructive. It shows the intended timing for both the bat throws and the charged swing, and most players lose distance simply by swinging early rather than by using the wrong character.
Bat throws do damage, and damage translates directly into distance. Skipping them to focus on the swing is the most common way to underperform.