If a person gives all his wealth in charity and has nothing left, if there is someone on whom he is obliged to spend, such as his children, wife and parents, and he does not have a job from which he can earn money to spend on them, it is not permissible for him to give all his wealth, because the Prophet (blessings and peace of Allah be upon him) said: “It is sufficient sin for a man to neglect his dependents.” Narrated by Abu Dawood; classed as saheeh by Shaykh al-Albaani (may Allah have mercy on him).
And he (blessings and peace of Allah be upon him) said: “If you leave your heirs independent of means, that is better than leaving them to beg from people.” Narrated by al-Bukhaari, 2742.
Because giving charity is naafil and spending on one’s children is obligatory, it is not permissible to give precedence to a naafil act over one that is obligatory.
It says in Asna al-Mataalib (1/407): If he gives in charity that which he needs for his dependents, that is not permissible, because of the report, “It is sufficient sin for a man to neglect his dependents” (narrated by Abu Dawood with a saheeh isnaad; a similar report was narrated by Muslim), and because supporting them is obligatory and takes precedence over that which is naafil. End quote.
It says in al-Furoo‘ (2/650): If a person wants to give all his wealth in charity, if he has dependents and they have enough to live on or he can earn enough for them, then it is permissible, because of the story of [Abu Bakr] al-Siddeeq (may Allah be pleased with him), otherwise it is not permissible. End quote.
He also said (2/650): Our companions said: If he will harm himself or those on whom he is obliged to spend by doing that, then it is a sin. End quote.
In Subul al-Salaam it says: al-Baaji, who is one of the Maalikis, said: It is haraam to use up all of one’s wealth in charity. End quote.
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said: This makes it clear that what is required is to start with that which is obligatory. The first obligation is to look after yourself; start with yourself and then those whom you support. But there may be some emergency situations in which giving precedence to people other than your family is more important, such as dealing with the urgent case of a starving person who is going to die. If you can save him by giving him food, and your family will not die if you do not feed them right now, then in this case we give precedence to the starving person so as to meet his urgent need. End quote from Sharh al-Kaafi.
The reason why it is haraam is if those on whom you are obliged to spend do not approve. But if they do approve, then there is nothing wrong with giving all of one’s wealth in charity.
It says in Mataalib Ooli al-Nuha (2/166): If a person gives something that will make him unable to meet the needs of one on whom he is obliged to spend, such as his wife or relative, then it is a sin, unless his dependents agree to give precedence to others over themselves, and this is better, because Allah says (interpretation of the meaning): “and give them (emigrants) preference over themselves even though they were in need of that” [al-Hashr 59:9].
And Allah knows best.