Who wrote the tale of Balaam?
The tale of Balaam, which goes across 3 chapter, and for 93 verses, is one of the longest story arcs to include a non-Israelite protagonist in a major role other than Pharaoh.
But who wrote it?
Moses was nowhere to be found in the story, and there were conversations and dealings that were taking place that are not referenced in any other text that mentions Balaam. It is as if the other books were aware that someone named Balaam was involved with the Moabites, and that it didn't turn out well for them, but that's it.
In fact, some of the other mentions of Balaam say things that we don't find in our narrative, such as "Yahweh would not listen to Balaam", and "God turned [Bilaam's] curse into a blessing".
So there was a general idea of someone who had a connection with Yahweh, and that he was hired to curse Israel, but Yahweh wouldn't listen, and He turned the curse into a blessing instead.
But that's not our Balaam story.
Let's look at those other 9 verses, that are outside of the main story, which talk about Balaam:
Nowhere in the Balaam story can you find Balaam telling the king to send sexy women into the Israelite camp, nor telling the king to seduce the Israelites into worshiping Baal Peor. Nor are any other Gods even mentioned.
As for Baal Peor:
An area that maybe had several thousand people, and the people saw several million people coming towards them, and the Moabites were afraid because these millions had just conquered the Ammomites. The idea that they weren't giving up their food and water to the approaching invaders is a strange complaint to make, never mind that there was not enough food and water to satisfy the Israelites. It's a justification.
As for hiring Balaam, we read in two places where he tells the king's men (22:18), and, later (24:13), the king, that it doesn't matter how much silver and gold they give him, whatever Yahweh wants, Balaam is not going to go against His desires. And this frustrated king Balak to no end!
Did the king actually hire Balaam?
We read (22:16-17) that the king asked Balaam to come, promising to honor him and that he would follow Balaam's instructions. The king never offers money, and none is mentioned with the exception that Balaam tells the king that gold and silver isn't going to change the outcome.
So "summoned" seems more suitable than "hired".
Where in the Balaam story does it say that Yahweh would not listen to Balaam? It says (23:4-5) that Balaam prepared and waited for Yahweh, who then put an "utterance" in the mouth of Balaam, who simply repeated it. At no point does it say that Balaam planned to curse, only that he was waiting on Yahweh (23:3) to tell Balaam what to do.
Yes, a curse was what Balak had in mind, but it was not what Balaam intended, who simply wanted to find out what Yahweh wanted, and speak that.
As already noted, how they got to slay him when he went back to his own people, whoever they were, is unknown. Also, the Hebrew word kosem (קוסם) is an odd title to give a man whose life seemed about listening and serving Yahweh. It's a belittling title when compared to Moses.
This isn't the story at all. Moab didn't rise up to fight Israel, and then sent for Balaam. In fact, they fought only after the event with the pretty ladies, and then blamed Moab because the Israelites were cavorting with them.
But at least he doesn't use the term "hired".
As already noted, there is nothing in the story which says that Yahweh wouldn't listen to Balaam. In fact, it says that Balaam sought only to listen and await instructions from Yahweh.
This one actually gets it right.
But who wrote it?
Moses was nowhere to be found in the story, and there were conversations and dealings that were taking place that are not referenced in any other text that mentions Balaam. It is as if the other books were aware that someone named Balaam was involved with the Moabites, and that it didn't turn out well for them, but that's it.
In fact, some of the other mentions of Balaam say things that we don't find in our narrative, such as "Yahweh would not listen to Balaam", and "God turned [Bilaam's] curse into a blessing".
So there was a general idea of someone who had a connection with Yahweh, and that he was hired to curse Israel, but Yahweh wouldn't listen, and He turned the curse into a blessing instead.
But that's not our Balaam story.
Let's look at those other 9 verses, that are outside of the main story, which talk about Balaam:
Numbers 31:8 - And they slew the kings of Midian, beside the rest of them who were slain; that is, Evi, and Rekem, and Zur, and Hur, and Reba, five kings of Midian; Balaam, the son of Beor, they also slew with the sword.
It should be noted that at the beginning of the story (22:4-7), we are introduced to the elders of Midian (and of Moab), who were apparently diviners since they carried their divining object back with them as they left Moab. and no "king of Midian" were even mentioned, never mind five kings.
And at the end of the story (24:14), Balaam tells Balak that he is returning back to his people, and gives the blessing, and then he leaves the presence of the king to "return to his place" (24:25).
So in Numbers 31, when Israel attacks Moab, there were no kings of Midian, and there certainly was no Balaam to be found. Putting aside his powers of prophecy, it was common sense for him to be as far away from the disappointed king as possible! This is something that Moses did not seem to be aware of, nor the writer of these other verses.
Numbers 31:16 - Behold, these caused the people of Israel, through the counsel of Balaam, to commit trespass against the Lord in the matter of Peor, and there was a plague among the congregation of the Lord.
Nowhere in the Balaam story can you find Balaam telling the king to send sexy women into the Israelite camp, nor telling the king to seduce the Israelites into worshiping Baal Peor. Nor are any other Gods even mentioned.
As for Baal Peor:
Deuteronomy 23:5 - Because [the Midianites] met you not with bread and with water in the way, when you came out of Egypt; and because they hired against you Balaam the son of Beor of Pethor of Mesopotamia, to curse you.
An area that maybe had several thousand people, and the people saw several million people coming towards them, and the Moabites were afraid because these millions had just conquered the Ammomites. The idea that they weren't giving up their food and water to the approaching invaders is a strange complaint to make, never mind that there was not enough food and water to satisfy the Israelites. It's a justification.
As for hiring Balaam, we read in two places where he tells the king's men (22:18), and, later (24:13), the king, that it doesn't matter how much silver and gold they give him, whatever Yahweh wants, Balaam is not going to go against His desires. And this frustrated king Balak to no end!
Did the king actually hire Balaam?
We read (22:16-17) that the king asked Balaam to come, promising to honor him and that he would follow Balaam's instructions. The king never offers money, and none is mentioned with the exception that Balaam tells the king that gold and silver isn't going to change the outcome.
So "summoned" seems more suitable than "hired".
Deuteronomy 23:6 - Nevertheless, your Yahweh-Elohim would not listen to Balaam; but your Yahweh-Elohim turned the curse into a blessing to you, because your Yahweh-Elohim loved you.
Where in the Balaam story does it say that Yahweh would not listen to Balaam? It says (23:4-5) that Balaam prepared and waited for Yahweh, who then put an "utterance" in the mouth of Balaam, who simply repeated it. At no point does it say that Balaam planned to curse, only that he was waiting on Yahweh (23:3) to tell Balaam what to do.
Yes, a curse was what Balak had in mind, but it was not what Balaam intended, who simply wanted to find out what Yahweh wanted, and speak that.
Joshua 13:22 - Also Balaam, the son of Beor, the sorcerer, did the people of Israel slay with the sword among those who were slain by them.
As already noted, how they got to slay him when he went back to his own people, whoever they were, is unknown. Also, the Hebrew word kosem (קוסם) is an odd title to give a man whose life seemed about listening and serving Yahweh. It's a belittling title when compared to Moses.
Joshua 24:9 - Then Balak the son of Zippor, king of Moab, arose and fought against Israel, and sent and called Balaam the son of Beor to curse you;
This isn't the story at all. Moab didn't rise up to fight Israel, and then sent for Balaam. In fact, they fought only after the event with the pretty ladies, and then blamed Moab because the Israelites were cavorting with them.
But at least he doesn't use the term "hired".
Joshua 24:10 - But I (Yahweh) would not listen to Balaam; therefore he blessed you; so I saved you from his hand.
As already noted, there is nothing in the story which says that Yahweh wouldn't listen to Balaam. In fact, it says that Balaam sought only to listen and await instructions from Yahweh.
Micah 6:5 - O my people, remember now what Balak king of Moab planned, and what Balaam the son of Beor answered him from Shittim to Gilgal; that you may know the righteousness of Yahweh.
This one actually gets it right.
Nechemia 13:2 - Because they did not meet the people of Israel with bread and with water, but hired Balaam against them, that he should curse them; but our God turned the curse into a blessing.
This is a repeat of Deuteronomy 23:5 (above) with only a few variants, and, like that other verse, it doesn't reflect the story in Numbers 22-24.
Summary
The story of Balaam and Balak is an interesting story that none of the other books (with perhaps Micah) were aware of. Even the later chapter of the Book of Numbers gets it wrong.
So that leaves the question: Who wrote the story of Balaam?
It is quite possible that there was some folklore about a magician hired by the hated Moabites, and even he couldn't fight Yaheweh, and the Moabites lost. And perhaps this tale grew and grew and the result was inserted into the Book of Numbers, to become chapters 22-24.
It is apparent that the people who wrote the rest of the Book of Numbers were not aware of the details of the longer version of the story, nor were most of the other authors of the other books.
And even if Moses did exist, there is no way that he would have known the details (excluding "God told him about it"), and then get them wrong a few chapters later when relating what little he did know to the Israelites.
It's something that is interesting to ponder.