All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
Abu Dawood narrated in his Sunan, and so did Imam Ahmad in his Musnad, as well as others from the Hadeeth on the authority of ‘Amr ibn Shuayb from his father from his grandfather ‘Abdullah ibn ‘Amr ibn Al-‘Aas that a woman said to the Prophet : “(You see) this son of mine, for him my stomach was a vessel, my breasts were (his) irrigators, my lap was (his) container, and his father divorced me and wants to take him away from me.” Thereupon, the Prophet said to her: “You are more deserving in fostering your child than him unless you remarry.”
This Hadeeth is evidence that the mother deserves and has more right in nursing her children than the father unless there is an impediment that prevents the mother from having this right; this ruling is indisputable, as Abu Baker As-Siddeeq adjudicated to this effect and nobody had objected; and also ‘Umar adjudicated the same during his reign.
The mothers are preferred than the fathers because the women are better in nursing (children), more capable, more patient, kinder, and had more time (for this type of job) than men.
As regards your question: If she gets married, she has to give up custody of her children to the father. Why? This does not sound fair….etc. The answer is that: Mother's rights for custody is waved by marriage according to the judgement of the Prophet as he neither spoke as he pleased, nor was he ever oppressive in his Judgement, so his Judgement can never be unfair. How can a Muslim say such words as if he is objecting to the Prophet’s teachings and commandments? If the mother gets remarried, the custody (of children) is not transferred to the father, as you mentioned. One could say: is it suitable that children be raised with the wife of their father instead of their mother? If the right for custody of the mother is waved by marriage or by any other reason that prevents the mother's right for custody, then the custody will be transferred to the women from the mother's side; this is the view of the three Imams and one of the two views of Imam Ahmad .
The view of the Hanafi School of jurisprudence:
The priority is given to the mother, then follows the mother's mother, after that the father's mother, then the sisters: sister from mother and father; then the sister from mother’s side, then the sister from the father’s side; then the maternal aunt, then the paternal aunt.
The view of the Maaliki School of jurisprudence:
The priority is given to the mother, then the mother's mother, then the maternal aunt, then the father's mother, then the latter's mother, then the sister, then the paternal aunt, then the niece.
The view of the Shaafi’i School of jurisprudence:
The priority is given to the mother, then the mother's mother, then it is transferred to those who inherit her mothers, then the sister, then the maternal aunt, then the paternal aunt.
The view of the Hanbali School of jurisprudence:
The priority is for the mother, then her mothers (i.e. the mother of the mother, and the grandmother of the mother, and so forth).
So you can see that the priority is given more to the women from the mother's side than the father himself as well as women from the paternal side.
As for your question: Should the children be raised by the stepmother instead of the real mother? We say: Is it (then) suitable that children be raised by the stepfather instead of the real father? There should be no interference to this with our intelligence; rather, we must refer to the Sharee’ah (Islamic Law). It is also suitable that we inform you that the custody of children is not waved by marriage only, but it is also disallowed by many other reasons, such as: dissoluteness, disbelief, and so forth. Moreover, custody is only for children who are less than seven years of age. If the male child reaches seven years of age, he will be asked to choose between his father and mother, and he will stay with whomever he chooses; but the female child will stay with her father after she reaches seven years of age. This is the view of the Hanbali School of jurisprudence.
As for your last question: will that person be rewarded for that? The answer is: Yes, Allah willing. If that husband raises the child of his wife in a good manner, and treats him/her well for the Sake of Allah, he will be rewarded; as Allah Says (what means):
• {But he who does of righteous deeds while he is a believer - he will neither fear injustice nor deprivation.} [Quran 20:112]
• {So whoever does an atom's weight of good will see it.} [Quran 99:7].
For more benefit on the custody of children and right of visiting them, please refer to Fataawa 326341, 86891, 87762, 88331, 89832, 182019, 213352, 82128, 341287, 84575, and 86053.
For more benefit on the sequence of relatives who have more right in the fostering of the children after their mother, please refer to Fataawa 90467 and 84618.
Allah knows best.