As has happened with practically every military superpower in the history of humanity, when Israel reached its most powerful point, flagrant moral corruption, which in turn led to every manifestation of idolatry, set in i.e. "proud" Sodomites and men and women defiantly committing public acts of fornication (it was the same process that later turned wise King Solomon into a typical carnal-minded king of the world, at a cost of Israel's unity - see The Israelite Monarchy - The Division Of Israel).
"While Israel dwelt in Shittim the people began to play the harlot with the daughters of Moab. These invited the people to the sacrifices of their gods, and the people ate, and bowed down to their gods. So Israel yoked himself to Baal of Peor. And the anger of The Lord was kindled against Israel; and The Lord said to Moses, "Take all the chiefs of the people, and hang them in the sun before The Lord, that the fierce anger of The Lord may turn away from Israel." And Moses said to the judges of Israel, "Every one of you slay his men who have yoked themselves to Baal of Peor [see also Baal-zebub and Beelzebub]." (Numbers 25:1-5 RSV)
The Levites seemed to be the least affected (Moses himself was a Levite); as they demonstrated many times before, although the Levites were the priesthood, they did not use their status as ministers of The Lord to shirk military or police duty, as in this case with Phinehas the son of Eleazar (see also The Lines Of Eleazar and Ithamar). Some have criticized his taking of life, but what Phinehas did, in obedience to The Lord's direct command, was to save life, many lives, perhaps thousands of lives, for the plague that would kill 24,000 people stopped because of what Phinehas did.
"And behold, one of the people of Israel came and brought a Midianite woman to his family, in the sight of Moses and in the sight of the whole congregation of the people of Israel, while they were weeping at the door of the tent of meeting. When Phinehas the son of Eleazar, son of Aaron the priest, saw it, he rose and left the congregation, and took a spear in his hand and went after the man of Israel into the inner room, and pierced both of them, the man of Israel and the woman, through her body. Thus the plague was stayed from the people of Israel. Nevertheless those that died by the plague were twenty-four thousand." (Numbers 25:6-9 RSV)
Numbers Chapter 26
The Lord then ordered another census to be taken of the Israelite men over age twenty. A previous census, approximately 40 years earlier, had been taken the year after the Exodus (see notes for Numbers Chapter 1) which showed a military-age population of 603,550 (Numbers 1:46). That generation had almost entirely died off, deliberately ("These were those numbered by Moses and Eleazar the priest, who numbered the people of Israel in the plains of Moab by the Jordan at Jericho. But among these there was not a man of those numbered by Moses and Aaron the priest, who had numbered the people of Israel in the wilderness of Sinai. For The Lord had said of them, "They shall die in the wilderness." There was not left a man of them, except Caleb the son of Jephunneh and Joshua the son of Nun," Numbers 26:63-65 RSV; see also A Journey Without A Destination); the census of the next generation, just prior to their entry into the promised land, showed a military-age male population of 601,730 (Numbers 26:51).
"After the plague The Lord said to Moses and to Eleazar the son of Aaron, the priest, "Take a census of all the congregation of the people of Israel, from twenty years old and upward, by their fathers' houses, all in Israel who are able to go forth to war." And Moses and Eleazar the priest spoke with them in the plains of Moab by the Jordan at Jericho, saying, "Take a census of the people, from twenty years old and upward," as The Lord commanded Moses." (Numbers 26:1-4 RSV)
The Lord does nothing in vain. The purpose of the census was to determine the soon to come tribal allocations of the promised land (see Tribal Lands).
"The Lord said to Moses: "To these the land shall be divided for inheritance according to the number of names. To a large tribe you shall give a large inheritance, and to a small tribe you shall give a small inheritance; every tribe shall be given its inheritance according to its numbers. But the land shall be divided by lot; according to the names of the tribes of their fathers they shall inherit. Their inheritance shall be divided according to lot between the larger and the smaller." (Numbers 26:52-56 RSV)
Numbers Chapter 27
The matter of Zelophehad's daughters (see the Fact Finder question below) provided two important precedents in law, both ancient (as in the case of Zelophehad's daughters themselves, and others for long after) and modern (The Lord's inheritance law as quoted below has been used as the basis for many man-made laws and even succession rules for some national kings and queens - including that of Britain)
"Moses brought their case before The Lord. And The Lord said to Moses, "The daughters of Zelophehad are right; you shall give them possession of an inheritance among their father's brethren and cause the inheritance of their father to pass to them. And you shall say to the people of Israel, 'If a man dies, and has no son, then you shall cause his inheritance to pass to his daughter. And if he has no daughter, then you shall give his inheritance to his brothers. And if he has no brothers, then you shall give his inheritance to his father's brothers. And if his father has no brothers, then you shall give his inheritance to his kinsman that is next to him of his family, and he shall possess it. And it shall be to the people of Israel a statute and ordinance, as The Lord commanded Moses.'" (Numbers 27:5-11 RSV)
With the Israelites about to cross the Jordan, Joshua was formally declared the successor of Moses, who would not be entering the promised land, yet (see Why Did Christ Put Moses To Death?).
"And The Lord said to Moses, "Take Joshua the son of Nun, a man in whom is the spirit, and lay your hand upon him; cause him to stand before Eleazar the priest and all the congregation, and you shall commission him in their sight. You shall invest him with some of your authority, that all the congregation of the people of Israel may obey. And he shall stand before Eleazar the priest, who shall inquire for him by the judgment of the Urim [see Urim And Thummim] before The Lord; at his word they shall go out, and at his word they shall come in, both he and all the people of Israel with him, the whole congregation." (Numbers 27:18-21 RSV)
Fact Finder: How did The Lord provide a marriage law among the Israelites that both protected the legal rights of women and the integrity of the assigned tribal boundaries?