What you have heard, that a man marries the person he deserves and who is similar to him in terms of righteousness or immorality is not correct. This is indicated by the following:
1 – The story that Allaah tells us of two of His noble Prophets, namely Nooh and Loot (peace be upon them), whose wives were disbelievers. Allaah says (interpretation of the meaning):
“Allaah sets forth an example for those who disbelieve: the wife of Nooh (Noah) and the wife of Loot (Lot). They were under two of our righteous slaves, but they both betrayed them (their husbands by rejecting their doctrine). So they [Nooh (Noah) and Loot (Lot)] availed them (their respective wives) not against Allaah and it was said: ‘Enter the Fire along with those who enter!’”
2 – Islam does not allow an adulterer to marry a chaste woman, and it does not allow a chaste man to marry an adulteress. This indicates that such a thing could happen, and indeed it happens often.
Allaah says (interpretation of the meaning):
“The adulterer — fornicator marries not but an adulteress — fornicatress or a Mushrikah; and the adulteress –fornicatress, none marries her except an adulterer — fornicater or a Mushrik [and that means that the man who agrees to marry (have a sexual relation with) a Mushrikah (female polytheist, pagan or idolatress) or a prostitute, then surely, he is either an adulterer — fornicator, or a Mushrik (polytheist, pagan or idolater). And the woman who agrees to marry (have a sexual relation with) a Mushrik (polytheist, pagan or idolater) or an adulterer — fornicator, then she is either a prostitute or a Mushrikah (female polytheist, pagan, or idolatress)]. Such a thing is forbidden to the believers (of Islamic Monotheism)”
3 – The Prophet (peace and blessings of Allaah be upon him) said that a woman may be married for her wealth, her beauty, her lineage or her religious commitment, and the fact that he (peace and blessings of Allaah be upon him) encouraged marrying the one who is religiously-committed indicates that marriages could occur for other reasons, so a man might marry a woman who is not like him.
It was narrated from Abu Hurayrah that the Prophet (peace and blessings of Allaah be upon him) said: “Woman are married for four things: for their wealth, their lineage, their beauty and their religious commitment. Marry the one who is religiously-committed, may your hands be rubbed with dust (i.e., may you prosper).”
(Narrated by al-Bukhaari, 4802; Muslim, 1466).
4 – The fact that the Prophet (peace and blessings of Allaah be upon him) commanded guardians to marry the women under their care to religiously-committed men indicates that something other than that could happen.
It was narrated that Abu Hurayrah said: The Messenger of Allaah (peace and blessings of Allaah be upon him) said: “If there comes to you one with whose religious commitment and character you are pleased, then marry (your daughter or other female relative under your care) to him, for if you do not do that there will be tribulation in the land and much corruption.”
Narrated by al-Tirmidhi, 1084; Ibn Maajah, 1967. Classed as saheeh by al-Albaani in al-Silsilah al-Saheehah, 1022.
So the one who is looking for a wife should look for one who is religiously-committed and has a good character; similarly, woman’s guardians should not marry them to anyone but those who are religiously-committed. For a man is influenced by those with whom he keeps company, especially if that lasts for a long time. The Prophet (peace and blessings of Allaah be upon him) said: “A man will follow the way of his close friend, so let each of you look at whom he takes as a close friend.” (Narrated by al-Tirmidhi, 2378; classed as hasan by al-Albaani in Saheeh al-Tirmidhi, 1937).
“A man will follow the way of his close friend” i.e., he will follow the habits and path of his friends; “So let each of you look” means, think long and hard about; “whom he takes as a close friend” means, whom he regards as a friend and a brother. So if you like a person’s religious commitment and character, take him as a close friend, and if not, then avoid him. For characteristics are easily copied and keeping company with people has an effect on whether you will be good or bad. Al-Ghazaali said: Sitting with and mixing with one whose interest is worldly gain will make you also seek worldly gains; sitting with and mixing with one who is an ascetic will make you care little for worldly gains, because following characteristics are easily copied and one could copy the characteristics of one's friend without even realizing.
From Tuhfat al-Ahwadhi.
With regard to the adulterer, he may be punished with regard to his family. A hadeeth to that effect was narrated, but it is mawdoo’ (fabricated), however the meaning may be correct. We have mentioned it, with comment, in question no. 22769.
And Allaah knows best.