PRE-EXISTENCE OF SOULS.
Is taught both in the Qur’an and the Traditions.
‘Ayishah relates that Muhammad said, “Souls before they became united with bodies were like assembled armies, and afterwards were dispersed and sent into the bodies of mankind.” (Mishkat, book xxii. ch. xvi.)
There is said to be a reference to this doctrine in the Qur’an:-
Surah vii. 171: “And when the Lord drew forth their posterity from the loins of the sons of Adam….”
The commentator, al-Baizawi, says God stroked Adam’s back and extracted from his loins his whole posterity, which should come into the world until the Resurrection one generation after another ; and that these souls were all assembled together like small ants, and after they had in the presence of the angels confessed their dependence upon God, they were again caused to return into the loins of Adam,” (See Tafsiru ‘l-Baizawi, in loco.)
Based on Hughes, Dictionary of Islam