"Take a sum of the congregation of the Children of Israel, after their families, by the houses of their fathers, by the number of names, every male by their polls; from twenty years old and upwards, all that are able to go forth to war in Israel" (verse 2). Why did G-d require Moshe to take a census of the Jewish people? Surely G-d doesn't need Moshe to count the people in order to know how many there are, for the verse states, "He counts the number of the stars, he calls them by their names" (Psalms 147; 4). If G-d can count and name all the stars of the heavens, spanning the vastness of the universe, surely He can know the number of a few hundred thousand people standing in the Sinai desert.
Perhaps it was for Moshe's benefit. If the Jewish nation had been a democracy it would have been necessary for Moshe to take a poll to understand the needs of his constituents, but since everything was done at G-d's command, what benefit or need would Moshe have for a census?
The Torah seems to imply that the census was related to war, only the men were counted, and only from the age of twenty, when they are suitable for battle. One could have made the mistake of thinking that there was a tactical purpose in this census to establish the strength of the army. However throughout history, Jewish armies have never won battles based on strength of numbers. When G-d told Gideon to gather men for the battle against Midian he made him send the majority of the army home before the battle. "And the L-rd said to Gideon, 'The people that are with you are too many for me to give Midian into their hands, lest Israel vaunt themselves against me saying, my own hand has saved me...'" (Shoftim 7; 2). G-d commands Gideon to whittle the size of the army down from 32,000 to 300! In the desert, when the Jews were totally reliant on miracles for their sustenance, certainly they did not need numerical strength to win battles. Rav Moshe Feinstein explains that this is the reason that the Torah stresses and repeats "As G-d commanded Moshe, and they counted them in the Sinai desert" (I; 19). Lest we make the mistake of thinking that Moshe counted the people for any strategic purpose, the Torah repeats that the census was taken solely because G-d had commanded it.
In answer to this question, Rashi begins his commentary on Numbers with the following: "Because the Jews are so dear to G-d, He counts them all the time. When they left Egypt He commanded a census be taken, after the incident of the Golden Calf, when many people died, He counted them to know the number remaining, and when He was about to rest His Holy Presence upon them He counted them. On the first of Nissan the Mishkan was erected, and on the first of Iyar He counted them."
How does G-d's commanding for a census to be taken show how dear the Children of Israel are to Him? Ibn Ezra (Psalms ibid.) says that there is a difference between the Hebrew words minyan, and mispar, both of which mean number in English. The former refers to the total of the whole, whereas the latter denotes individuality within the group. It is the word mispar which is used in the taking of this census. Similarly, the people are to be counted according to "the number of names". A name represents the potential, uniqueness and the individuality of a person. By instructing Moshe to count the people, G-d is telling them that each person has a unique role to fulfil within the nation. Everyone is a vital part of G-d's plan. This is a clear message from G-d to the nation, showing them their importance. This explains why G-d commanded the census to be taken, and why Rashi describes it as showing how dear the Jewish nation is to G-d.