(Bamidbar 31:4) "A thousand to a tribe, a thousand to a tribe": 24,000 all together, viz. (Ibid. 5) "And there were handed over … twelve thousand armed for the host, etc." R. Akiva says: "a thousand to a tribe, a thousand to a tribe." Why (add) "And there were handed over, etc." To exclude the tribe of Levi. "And there were handed over of the thousands of Israel": Scripture hereby apprises us that they were just and righteous men, who gave of themselves for the cause.
R. Nathan says: Others handed them over: "This man is kasher — Let him go! This man is a tzaddik — Let him go!" R. Elazar Hamodai says: Come and see the love (of Israel for) the shepherd of Israel. So long as they had not heard that the death of Moses was attendant upon the war with Midian, what is written of them? (Shemot 17:4) "Just a little more and they will stone me."
When they heard of it, they began hiding (to avoid conscription, so as not to be instrumental in his death) — notwithstanding which they were conscripted perforce, viz. "And there were handed over of the thousands of Israel, etc."