The essence of baseball is some guy trying to throw a ball past another guy who is trying to hit said ball with a stick. Sometimes, the guy who is throwing the ball misses their intended location. In some of those situations, the ball could hit the other guy with the stick, who is standing pretty close to the intended location of the thrown ball, after all. This is unavoidable and is part of the fabric of the game.
For professional baseball, however, the consequences of this happening are high. Not so much for the pitcher—if a pitcher hits a batter, the batter takes first base, no different than a walk or a single—but very much for the batter.