The basic principle with regard to contracts and conditions is that they are permissible and valid, and none of them are haraam or invalid except that which is contrary to shareeah.
Stipulating that the husband should be deprived of inheriting in the event of the wife's death is a condition that is contrary to shareeah, because it is cancelling out the right of the husband that Allah granted him to a share of his wife's wealth in the event of her death.
Al-Bukhaari and Muslim (1504) narrated from Aa'ishah (may Allah be pleased with her) that she said: The Messenger of Allah (blessings and peace of Allah be upon him) said: What is the matter with people who stipulate conditions that are not in the Book of Allaah? There is no condition that is not in the Book of Allaah but it is invalid, even if there are one hundred conditions. The Book of Allaah is more deserving of being followed and the conditions of Allaah are more binding.
Al-Qurtubi (may Allah have mercy on him) said:
i.e., conditions that are not acceptable according to shareeah are invalid even if they are many.
End quote from Fath al-Baari, 5/189
Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) said:
Whoever stipulates conditions in a waqf, manumission, a gift, a sale, a marriage contract, rental, vow and so on that is contrary to what Allah has decreed for His slaves in that those conditions enjoin something that Allah has forbidden or forbid something that Allah has enjoined, or they permit something that He has prohibited or prohibit something that He has permitted, then these conditions are invalid according to the consensus of the Muslims of all eras.
End quote from Majmoo al-Fataawa, 31/28
He also said:
If a condition is contrary to the conditions of Allah and His Messenger, it is invalid, such as if he stipulates that his son or his relatives should not inherit from him, or that he should help him in everything he wants and support him against everyone who opposes him whether he is in the right or otherwise, or that he should obey him in everything he tells him to do, and other such conditions.
And when such conditions are made, then one should fulfil the part of it (the contract) that is in accordance with the commands of Allah and His Messenger (blessings and peace of Allah be upon him), and he should not fulfil the part that is contrary to that. This is agreed upon among the Muslims.
End quote from Majmoo al-Fataawa, 35/97
And Allah knows best.
Reproduced from Islam QA