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.
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.
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.