In this week's Parsha, Hashem commands Moshe to count Bnai Yisrael (במדבר א':א'-מ"ו). At first glance, this commandment to count seems to come without any reason whatsoever. It also seems that this counting doesn't flow from the last couple of Parshiyos in the previous Sefer, Sefer VaYikra. For what reason,then, does Hashem all of a sudden command Moshe to count Bnai Yisrael? Rashi (לפסוק א' שם בד"ה וידבר) writes that because of Hashem's love for Bnai Yisrael, He counts them every so often. He notes that Hashem counted them on the first of Nissan, when the Mishkan was put up, and He counted them now again on the first of Iyar, as a sign of His love for them. However, the question of why the instruction was given specifically at this juncture still remains.
In describing exactly who will be counted, the Torah refers to those who will be in the צבא, the army (שם פסוק ג'). Rashi (שם בד"ה כל) writes that we learn from the word צבא and the fact that Moshe counted only those from the age of twenty and up that no one can go to the army unless they are over the age of twenty. The Ramban (שם בד"ה כל), though, disagrees, and writes that the word צבא doesn't refer to Bnai Yisrael's army, but rather refers to any gathering of the people. Therefore, when the Posuk says that Moshe should count them לצבאותם, according to their צבא, (שם), it was referring to the Shevatim, the tribes, because they were large gatherings of people, and the implication is that the count had nothing to do with the army.
However, the Ramban admits later on in the Parsha (פסוק מ"ה שם בד"ה ויהיו) that indeed this counting was done for military purposes. He explains that it was the practice of many emperors that before they would go out to war, they would take a census of who was fighting. Since Bnai Yisrael were preparing to go to war with those who occupied Eretz Yisrael, Hashem commanded Moshe to count Bnai Yisrael. However, it was only the males over twenty years old who were to be counted, because they were the ones who would be fighting. This is the reason why the Posuk says כל יצא צבא בישראל, referring to those going to the army (שם פסוק ג'), because the purpose of this counting was to know how many people were to go to war. This would stand in contrast to the counting of the Leviyim done later on in the Parsha, in which the counting was done starting from the age of one month and up (שם ג':ט"ו), because that count had nothing to do with the army.
The Ramban earlier (ויקרא כ"ה:א' בד"ה וידבר) explains how the whole end of Sefer VaYikra is a description of Moshe establishing the second Bris, or covenant, with Bnai Yisrael. Even though in the first Bris, described in Parshas Mishpatim, Shemittah was mentioned only in passing, in the second Bris, it was mentioned in detail with many conditions attached to it, as set out in the Tochachah, the warnings given to Bnai Yisrael. He explains (שם) that Bnai Yisrael's continued existence in the land is dependant on the people keeping the Shemittah. In fact, the Ramban explains elsewhere (שם כ"ו:ט"ז בד"ה וטעם אף), discussing portions of the Tochachah, that Bnai Yisrael were put into exile because of the years in which they didn't keep the Shemittah. One can see, then, that the establishing of the Bris the second time was aimed towards Bnai Yisrael's anticipated arrival in Eretz Yisrael in a short matter of time, and hence the references to Mitzvos relating to the land. If this is the case, then the counting that comes at the beginning of our Parsha fits right in. As Bnai Yisrael are preparing to wage war against the nations of who blocked their way to inheriting Eretz Yisrael, Hashem commands Moshe to take a count of whoever is going to be going into the war.