For this you need the item: The Sandman, which is unlocked after obtaining 16 scout achievements, by random drop, or by trading.
https://wiki.teamfortress.com/wiki/SandmanYou then need to click Mouse 2 in order to throw baseballs at enemies. If it hits them, it will stun them. The further away the hit, the longer they are stunned.