Another interpretation (of Numbers 26:2): Why did he count them? The matter is like a shepherd to whom the householder handed over his flock by number. When he has completed his guarding, when he returns them, he must count them. So too when Israel went out from Egypt, He handed them over to Moses by number, as it is written, "And the LORD spoke to Moses in the wilderness of Sinai... Take a census..." (Numbers 1:1-2). And also when they went out it is written, "And the children of Israel journeyed from Rameses to Succoth, about six hundred thousand men on foot" (Exodus 12:37). Behold, he received them by number. When he came to depart in the plains of Moab, he returned them by number.
Why Moses Counted Israel Like a Shepherd Returning the Flock
Midrash Tanchuma Buber, Pinchas 6:2
ד"א למה מנה אותם, משל לרועה שמסר לו בעל הבית צאנו במנין, השלים שמירתו כשמחזירן צריך למנותן, וכשיצאו ישראל ממצרים מסרן למשה במנין, דכתיב וידבר ה' אל משה במדבר סיני [וגו'], שאו את ראש [וגו'] (שם א א ב), ואף כשיצאו כתיב ויסעו בני ישראל מרעמסס סכותה כשש מאות אלף רגלי (שמות יב לז), הרי קיבלן במנין, בא להפטר בערבות מואב החזירן במנין.