Balaam's second prophecy, from which you quote, may not be reliable. The context of this passage is the story of a Moabite king Balak and questionable prophet named Balaam. Consider the introduction to the story from Numbers 22-24.
Numbers 22:4-7 And Balak the son of Zippor was king of Moab at that time. So he sent messengers to Balaam the son of Beor, at Pethor, which is near the River, in the land of the sons of his people, to call him, saying, “Behold, a people came out of Egypt; behold, they cover the surface of the land, and they are living opposite me. Now, therefore, please come, curse this people for me since they are too mighty for me; perhaps I may be able to defeat them and drive them out of the land. For I know that he whom you bless is blessed, and he whom you curse is cursed. So, the elders of Moab and the elders of Midian departed with the fees for divination in their hand; and they came to Balaam and repeated Balak’s words to him.”
It's a good story that spans Numbers 22-24. Balaam is clearly not a prophet being consulted. He is a diviner who is collecting a fee from the enemy of the Isrealites to communicate with their God in order to obtain a curse upon them. Balaam and the King sacrifice animals to Yahweh, and Balaam is successful1 in his attempt to contact Yahweh, who forbids Balaam to place a curse on Israel, and so he pronounces a blessing instead. However, presumably in the interest of collecting the fee, Balaam continues to work with Balak to divine a curse against Israel.
Numbers 23:13-16 Then Balak said to him, “Please come with me to another place from where you may see them, although you will only see the extreme end of them and will not see all of them; and curse them for me from there.” So he took him to the field of Zophim, to the top of Pisgah, and built seven altars and offered a bull and a ram on each altar. And he said to Balak, “Stand here beside your burnt offering while I myself meet the Lord over there.” Then the Lord met Balaam and put a word in his mouth and said, “Return to Balak, and thus you shall speak.”
Yahweh commands that Balaam speaks a blessing over Israel. The discourse that Balaam then makes is the source of your verse. After the discourse, Balak again suggests that they visit another place and try to obtain a curse instead. Balaam repeats the routine, hoping again for a different result. Indeed, this third time the Spirit of Yahweh enters Balaam.
Numbers 23:27-24:3 So Balak took Balaam to the top of Peor which overlooks the wasteland. Balaam said to Balak, “Build seven altars for me here and prepare seven bulls and seven rams for me here.” Balak did just as Balaam had said, and offered up a bull and a ram on each altar. When Balaam saw that it pleased the Lord to bless Israel, he did not go as at other times to seek omens but he set his face toward the wilderness. And Balaam lifted up his eyes and saw Israel camping tribe by tribe; and the Spirit of God came upon him.
Balaam's usual procedure is the reading of omens. He is a diviner, not a prophet. A passage cited below tells us that Balaam is from Mesopotamia not Israel so it's likely that these sacrifices are not being offered to God in the prescribed way. The Scripture says that The Spirit of Yahweh came over him (v. 24:2), but only after he had delivered the discourse from which you quote (23:7) and sacrificed animals upon strange fire2 a third time, after Yahweh had already delivered his word twice.
Balaam then pronounces a blessing over Israel that sounds like genuine prophecy. He blesses Israel, then speaks to the Canaanite kings saying, "And now, behold, I am going to my people; come, and I will advise you what this people will do to your people in the days to come.” He pronounces destruction over them, and then3 announces the coming Messiah.
As I said, it's an interesting story. It ends with Belaam and Balak simply parting ways, though we find much later in our reading that the Israelites put Balaam to death by the sword for practicing divination:
Numbers 31:8 They killed the kings of Midian along with the rest of their slain: Evi and Rekem and Zur and Hur and Reba, the five kings of Midian; they also killed Balaam the son of Beor with the sword.
Deuteronomy 23:3-5 No Ammonite or Moabite shall enter the assembly of the Lord; none of their descendants, even to the tenth generation, shall ever enter the assembly of the Lord, because they did not meet you with food and water on the way when you came out of Egypt, and because they hired against you Balaam the son of Beor from Pethor of Mesopotamia, to curse you. Nevertheless, the Lord your God was not willing to listen to Balaam, but the Lord your God turned the curse into a blessing for you because the Lord your God loves you.
Joshua 13:22 The sons of Israel also killed Balaam the son of Beor, the diviner, with the sword among the rest of their slain.
Balaam is remembered as immoral, even in the Revelation to John:
2 Peter 2:15 forsaking the right way, they have gone astray, having followed the way of Balaam, the son of Beor, who loved the wages of unrighteousness;
Jude 1:11 Woe to them! For they have gone the way of Cain, and for pay they have rushed headlong into the error of Balaam, and perished in the rebellion of Korah [cf. Numbers 16].
Revelation 2:14 But I have a few things against you, because you have there some who hold the teaching of Balaam, who kept teaching Balak to put a stumbling block before the sons of Israel, to eat things sacrificed to idols and to commit acts of immorality.
Because of these, Balaam's first and second prophecies, from before the Spirit entered into him, might be called into question.
1. I like to think that this does not imply that Balaam was a prophet or even a genuine diviner, only that the Spirit he was attempting to contact in this case was genuine, and had something to say to the enemies of his people.
2. cf. Leviticus 10:1
3. Suprise!