Prisons got built because societies could afford them. Before that, criminals were banished, executed, dismembered, enslaved, or marked. There wasn't wealth enough to hire people to watch them round-the-clock.
Baseball used to need the beanball because there was little other way to enforce protection for one's teammates. There were rules to how it might be used, but it was controlled violence. Bats, hardballs, cleats, and running bodies could cause injuries, and without some way of setting limits, a mean and violent team could simply intimidate and roughhouse another team into submission. A century ago and earlier, that is often what did happen. Players came into hostile places and some of them were violent. No one was likely to be arrested for on-field conduct, and no one wanted leagues or barnstorming tours where there was a fight every game.
Everything is on film now and can be reviewed. Players can be fined or suspended. Allowing brushback and other "enforcement" pitches actually interferes with that now, as questions of who started, and who escalated a situation get more complicated. I differentiate here between the cat-and-mouse game between batter and pitcher over control of the plate and the "protecting my teammates" knockdown pitches we have been seeing between the Red Sox and Orioles recently.
It's part of the game. But it doesn't have to be. It served a purpose when there was no other enforcement.