Well, it wasn’t YHWH directly, it was two she bears working for him who mangled the boys. But God sent the bears because one of his prophets was angry and hurt because the boys made fun of him.
Here’s what happened: Elisha (a B-list prophet working for the more famous Elijah) is traveling to Bethel after his boss Elijah smites some waters to allow unspecified “sons of prophets’” to walk between the separated waters of the Jordan River. Yes, this is similar to the crossing of the Red Sea, but not as big a deal*
As Elijah’s understudy, Elisha now has possession of his master’s magic mantle and all the responsibilities that go with it. Elijah has just been taken up into the whirlwind amid chariots of fire and so on, so it is understandable that Elisha is a bit on edge.
So when a bunch of kids come around and begin mocking his bald spot, it is understandable that he curses them via his special relationship with the Creator of the Universe.
“And he went up from thence unto Beth-el; and as he was going up by the way, there came forth young lads out of the city, and mocked him, and said unto him, Go up, thou baldhead; go up, thou baldhead. 24 And he looked behind him and saw them, and cursed them in the name of Jehovah. And there came forth two she-bears out of the wood, and tare forty and two lads of them. And he went from thence to mount Carmel, and from thence he returned to Samaria.” - 2 Kings 2
It is not clear whether Jehovah’s bad news bears actually murder the boys or just maul them. Some translations say “tare” (KJV) and others, more explicitly, say “ripped to pieces.” (New English Translation). Either way, death by bear mailing is pretty tough love by anyone's standards.
Why bears? Why female bears? We are not given to know the mind of god, especially when he is in this kind of mood. However, I don’t mind tempting Fate by noting the punishment seems excessive for the actual crime. But then, YHWH is an arbitrary and (let’s face it) bloodthirsty deity who doesn’t mind violating his own commandments. But when you’re god, there are no consequences.
If you are looking for clues as to the vicious authoritarianism of bible literalists, this is another example. It's why we do the Fun Bible Stories series.
_______________________________________________________________________________
*It is one of three water smiting events in the Hebrew Bible.