‘Aa’ishah (may Allaah be pleased with her) said: “I heard the Prophet (peace and blessings of Allaah be upon him) saying:
الأَرْوَاحُ جُنُودٌ مُجَنَّدَةٌ فَمَا تَعَارَفَ مِنْهَا ائْتَلَفَ وَمَا تَنَاكَرَ مِنْهَا اخْتَلَفَ
‘Souls are like conscripted soldiers; those whom they recognize, they get along with, and those whom they do not recognize, they will not get along with.’”
Al-Imaam Abee Sulaymaan Hamad b. Muhammad Al-Khattaabee said:
“This can be interpreted in two ways: First of the two; that this may refer to their similarity as regards good or evil, righteousness or corruption. Good people are inclined towards other good people, and evil people are similarly inclined towards other evil people. Souls feel affinity with others according to the nature in which they were created, good or evil. If souls’ natures are similar, they will get along, otherwise they will not be on good terms with one another.
The other way; is that is being referred to khabar about the beginning of creation in the realm of the unseen when, it is reported, souls were created before bodies, and used to meet one another and express their pessimism about the future. When souls have entered bodies (come to the physical realm) they may recognize one another from the past, and may be on friendly terms or otherwise based on that past experience, and Allah knows best.”
[A’laam al-Hadeeth – Sharh Saheeh Al-Bukhaaree]