Do any commentaries discuss why Hashem told Moshe to take a census in parshas Bamidbar? Hashem knew how many people there were and censuses are generally forbidden, so what was the point in the exercise?
2 Answers
Rashi on Bamidbar 1:1 says
מתוך חיבתן לפניו, מונה אותם כל שעה. כשיצאו ממצרים מנאן. וכשנפלו בעגל מנאן, לידע מניין הנותרים. כשבא להשרות שכינתו עליהן, מנאן. באחד בניסן הוקם המשכן, ובאחד באייר מנאם
Which basically means that the count was to demonstrate how precious they were to him that they were constantly being counted.
The Kli Yokor says that this took place one month after the Mishkan was built. There was a need to establish a minimum count of people for the Mishkan to operate. (The reason for that seems partly kabbalistic so I do not understand it well enough to explain it).
Rashbam on Bamidbar 1:2 (text copied from Sefaria)
שאו את ראש כל עדת - לפי שמעתה צריכים לבוא לארץ ישראל ובני עשרים ראוים לצאת בצבא המלחמה, שהרי בעשרים בחדש השני הזה נעלה הענן, כדכתיב בפרשת בהעלותך, וכתיב שם: נוסעים אנחנו אל המקום וגו' ולכך צוה הקב"ה בתחלת חודש זה למנותן
focuses on the fact that Bnai Yisrael are about to move towards their journey to conquer Eretz Yisrael and the reason that he gives for the census being taken at this point is to count those of military age - those who go out to war.
The view of several commentators is that the earlier census in Ki Tissa in which a half shekel was collected from each person counted was for the purpose of raising funds for the Mishkan rather than primarily to count the population.
To answer @AA's question on the census in Pinchas - see Rashi on Bamidbar 26:1 where he gives a parable to explain the reason for the census there. It was after a plague and was like his could be compared to a shepherd whose flock was attacked by wolves and a shepherd some of whose sheep were killed - he counted them to know how many were left.