When Does Child Custody End?
Question

Up to what age does a teenager or child need custody? Can the nursing infant remain with his mother if she remarries? Is the mother required to spend money on her children after their custody ends, buying a house for them and spending on them? What if there is a daughter; who should spend on her until she marries, after custody ends?
Praise be to Allah.Who has more right to custody in Islam? 
Custody of the child is a right that is shared by the spouses if they are still married. If divorce occurs, then the mother has more right to custody .
Al-‘Adawi Al-Maliki said in his commentary on Sharh Al-Khurashi (4/207): “Custody belongs to the mother, if she is divorced or her husband dies. But whilst she is still married, custody belongs to both spouses.”
It says in Al-Mawsu‘ah Al-Fiqhiyyah (17/301): “Custody of the child belongs to both parents, if they are still married . If they separate, then custody belongs to the mother, according to scholarly consensus.”
The mother has more right to custody of her children until the age of seven, so long as she has not remarried, because of the report narrated by Ahmad (6707) and Abu Dawud (2276) from ‘Abdullah ibn ‘Amr (may Allah be pleased with him) who said: A woman said: O Messenger of Allah, my womb was a vessel for this son of mine, my breast gave him to drink, and my lap was a protection for him. But now his father has divorced me and wants to take him away from me. The Messenger of Allah (blessings and peace of Allah be upon him) said to her: “You have more right to him so long as you do not remarry.” 
This Hadith was classed as sound by Al-Albani in Sahih Abu Dawud.
Who gets child custody after a mother's marriage?
If she (the mother) remarries, custody passes to the next in line. However, there was a difference of opinion among the jurists concerning that:
Some of them are of the opinion that it passes to the mother’s mother . This is the view of the majority in the four Madhhabs.
Others are of the opinion that it passes to the father. This is the view favoured by Shaykh Al-Islam Ibn Taymiyyah and Ibn Al-Qayyim (may Allah have mercy on them). (See: Al-Mawsu‘ah Al-Fiqhiyyah, 17/302) and Ash-Sharh Al-Mumti‘, 13/535)
If we say that custody transfers to the child’s father, then if he allows the child to remain with his mother who has remarried, and she is suitable for the responsibility of custody, and her second husband agrees: then there is no objection.
Similarly, the mother’s mother may give up custody to her daughter who has remarried.
Shaykh Ibn ‘Uthaymin (may Allah have mercy on him) said: “Custody is the right of the one who can take care of the child, but it is not a duty.
Based on that, if he or she wants to give up custody to the next in line, it is permissible for him or her to do that." (Ash-Sharh Al-Mumti`,  13/536)
Who gets child custody after reaching the age of seven?
If the woman has not remarried and the child reaches the age of seven years,

If the child is male, he is given the choice between his father and his mother, and he will live with the one whom he chooses, because of the report narrated by An-Nasa’i (3496) and Abu Dawud (2277) from Abu Hurayrah (may Allah be pleased with him), who said: I heard a woman who came to the Messenger of Allah (blessings and peace of Allah be upon him) when I was sitting with him and said: O Messenger of Allah, my husband wants to take my son away even though he brings me water from the well of Abu `Inabah and is of benefit to me.

The Messenger of Allah (blessings and peace of Allah be upon him) said: “Draw lots for him.”
Her husband said: Who is disputing my right to my child?
The Prophet (blessings and peace of Allah be upon him) said [to the child]: “This is your father and this is your mother; take the hand of whichever of them you wish.”
And the child took the hand of his mother, and she took him away.
This Hadith was classed as authentic by Al-Albani in Sahih Abu Dawud.
This is the view of the Hanbalis and Shafi`is (may Allah have mercy on them).

If the child is female, she may also be given the choice, according to Ash-Shafi`i (may Allah have mercy on him).

Abu Hanifah (may Allah have mercy on him) said: “The mother has more right to her until the girl gets married or begins to menstruate.”
Malik (may Allah have mercy on him) said: “The mother has more right to her until she gets married and the husband consummates the marriage with her.”
Ahmad (may Allah have mercy on him) said: “The father has more right to her, because the father has more right to ensure her wellbeing.” (See: Al-Mawsu‘ah Al-Fiqhiyyah, 17/314-317)
When does child custody end?
Child custody ends when the child reaches puberty and the age of maturity, at which time he may choose whichever he wishes of his parents. The child also has the right to live separately from them if he is male.
Ibn Qudamah (may Allah have mercy on him) said: No one is entitled to custody over anyone else except a child or one who has an intellectual disability. As for one who is an adult of mature thinking, there is no need for custody of him, and he has the choice to live with whichever of his parents he wishes.
If he is a male, then he has the right to live alone, because he has no need of them, but it is recommended for him not to live apart from them so that he will not stop honouring them.
If the child is female, she cannot live on her own, and her father should prevent her from doing that, because there is no certainty that someone may come to her and corrupt her, thus bringing shame upon her and her family. If she does not have a father, then her guardian and her family should prevent her from doing that."(Al-Mughni  8/191).
Who spends on a child during custody?
Spending on the children’s maintenance during custody is the duty of the father.
After the custody ends, when the children reach puberty and become mature, then there is a difference of opinion among the jurists regarding the duty of spending on their maintenance.
If an adult son is poor, then his rich father is obliged to spend on him. If there is no father, then his rich mother must spend on him, according to the Hanbalis, whether he is healthy or incapacitated.
According to the Shafi`is, that becomes obligatory if the child is incapacitated due to a chronic condition or illness.
It says in Al-Insaf (9/289): “The words “and his children, no matter how far the line of descent reaches” also include adult children who are healthy and strong, if they are poor. This is correct, and it is the view of the Madhhab.”
Ibn Qudamah (may Allah have mercy on him) said: Ash-Shafi`i said: 
“There should be a condition that there is something wrong with him, either in terms of discernment or physically.
Abu Hanifah (may Allah have mercy on him) said: “The father should spend on the boy until he reaches puberty, then if he reaches puberty and is healthy, the duty to spend on him ceases, but the duty to spend on a daughter is not waived until she gets married.”
Malik (may Allah have mercy on him) said something similar, except that he said that spending on daughters should continue until they get married and their husbands consummate the marriage with them, then there is no spending on them even if they get divorced. But if they get divorced before consummation of the marriage, then [the father] should still spend on them.
We also have the words of the Prophet (blessings and peace of Allah be upon him) to Hind: “Take what is sufficient for you and your children on a reasonable basis.” He did not exempt the child who is mature and healthy, and because the child is poor, he deserves maintenance from his rich father, just as is the case if the child is chronically ill or blind." (Al-Mughni  9/258)
From this we may learn that so long as the father is alive, the woman does not have to spend on her children after custody ends, whether that is to buy a house or anything else, and that the father is required to spend on his daughter until she gets married.
For more details, please see the following category: Custody
And Allah knows best.