Praise be to Allah.
Imaam al-Bukhaari (may Allaah have mercy on him) reported in his Saheeh that Aaishah (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.(Saheeh al-Bukhaari, Kitaab Ahaadeeth al-Anbiyaa, Baab al-Arwaah junood mujannadah).
Ibn Hajar (may Allaah have mercy on him) said in his commentary on the hadeeth: Concerning the phrase Souls are like conscripted soldiers al-Khattaabi said: 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. It could be that what is being referred to is 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.
Someone else said: What it means is that when souls are created, they are made in two parts, and when the bodies in which the souls reside meet in this world, they either get along together or do not, based on the way in which these souls are created in this world.
I say that this is not contradicted by the fact that some people who do not like one another at first may get along well later on, because the hadeeth is probably speaking about the moment of first meeting, which has to do with the original creation and nothing else. If they dislike one another at first but later come to like one another, it is because of something new, a new quality that makes them love one another after the initial dislike, such as a kaafir becoming a Muslim or a sinner being reformed.
The phrase conscripted soldiers refers to different types or classifications, or groups brought together. Ibn al-Jawzi said: What we learn from this hadeeth is that when a person finds that he feels dislike towards someone who is known to be virtuous or righteous, he should try to find out the reason for that so that he can make the effort to rid himself of something undesirable. The opposite (if a person finds himself liking someone who is known to be evil) also applies. Al-Qurtubi said: Although they are all souls, they differ in different ways, so a person will feel an affinity with souls of one kind, and will get along with them because of the special quality that they have in common. So we notice that people of all types will get along with those with whom they share an affinity, and will keep away from those who are of other types. [Birds of a feather flock together Translator]. We may also note that within any given group or type, people may get along with some and dislike others, and this is in accordance with issues or qualities that form the basis of love or hate.
We have narrated a mawsool report in Sunan Abi Yalaa, at the beginning of which is the story narrated from Amrah bint Abd al-Rahmaan, who said: There was a woman in Makkah who liked to joke, and she came and stayed with a woman in Madeenah who was like her. When Aaishah heard about this, she said, My beloved spoke the truth. I heard the Messenger of Allaah (peace and blessings of Allaah be upon him) saying and mentioned a similar hadeeth.
The hadeeth was also narrated by Muslim in his Saheeh, 4773. Al-Nawawi said: With regard to the words of the Prophet (peace and blessings of Allaah be upon him), 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, the scholars said that the meaning is groups gathered together, or different types. As for them getting along, this happens because of something in common between them that Allaah has created. It was said that they are similar attributes that Allaah has created in them, or that they were created in a group and then dispersed in their bodies, so people who have similar characteristics will like one another, and those who do not have similar characteristics will not like one another. Al-Khattaabi and others said: this getting along with one another has to do with what Allaah decreed from the outset about the ultimate destiny of souls, whether they will be among the blessed [in Paradise] or the doomed [in Hell]. Souls are of two opposing kinds, and when they meet in this physical world, they will either love or hate one another depending on the way they were created. Good souls will be inclined towards other good souls, and evil souls will be inclined towards other evil souls. And Allaah knows best.