Imām al-Bukhārī and Imām Muslim both relate from Anas bin Mālik (رضي الله عنه) that he heard the Messenger of Allāh (صلى الله عليه وسلم) saying:
Whoever is pleased that his sustenance is expanded and his lifespan is extended, then let him keep the ties of kinship.
Shaykh al-Albānī stated:
The ḥadīth upon its apparent meaning is that Allāh—from His wisdom—has made keeping the ties of kinship to be a legislated method for a long life. Likewise, good manners and being a good neighbour, as occurs in some authentic traditions. This does not conflict with what is known by necessity from the religion that lifespan is determined. This is because [the determination of lifespan] is by way of the final outcome [the point of death], similar to whether one is happy or wretched (in the hereafter). Both of these are determined in relation to individuals, thus they are either wretched or happy. And it is also known definitively that happiness and wretchedness are both tied to legislated causes (asbāb). And just as faith increases and decreases with its increase being through obedience and its decrease being through disobedience—without that conflicting with what is in the Preserved Tablet [regarding the final outcome], then likewise is the lifespan. It increases and decreases when looked at from the angle of the ways and means (the asbāb, the adopted causes). It does not conflict with what is in the Preserved Tablet either”.
Shaykh al-Islām Ibn Taymiyyah said (in Majmūʿ al-Fatāwā 8/517):
The determined period (ajal)—[of a person’s lifespan]—is of two types. An absolute period which Allāh knows and a qualified period. Through this [distinction], the meaning of his saying (صلى الله عليه وسلم): “Whoever is pleased that his sustenance is expanded and his lifespan is extended, then let him keep the ties of kinship” becomes clear. For Allāh ordered the angel to write as part of his determined period, ‘If he keeps ties of kinship then increase him such and such’. And the angel does not know whether it will be increased or not. However, Allāh knows that which the affair willl settle upon. So when that time comes, it will not be hastened nor delayed.
Shaykh Ṣāliḥ al-Fawzān said (in al-Muntaqā in Fatāwā 1/98):
It’s meaning is that Allāh—the Sublime and Exalted—has promised the one who keeps his ties of kinship that He will reward and recompense him by increasing his lifespan, and that He will expand his sustenance for him, as a reward for his goodness.
And there is no contradiction between this ḥadīth and between the ḥadīth which states that the lifespan and sustenance of a person have been determined for him whilst he was in the womb of his mother. This is because there are ways and means (asbāb) which Allāh has made into the causes of a prolonged life and ways and means for sustenance. This ḥadīth indicates that benevolence and keeping family ties is a cause of prolonging lifespan and a cause of increase in sustenance. And Allāh is the one who decrees all affairs and places all cause and effect mechanisms. There are things which Allāh—the Sublime and Exalted—has decreed and which He has tied to certain causes, to result from them when these causes are brought, fulfilling their conditions and being absent of their barriers. [When this happens], the effects will then take place, all of this happening due to the decree (qadar) and recompense (jazāʾ) from Allāh, the Sublime and Exalted.
The above answers are very clear in removing the confusion that sometimes appears among Muslims regarding the expansion of life and sustenance. To illustrate with an example, a person who lives dangerously and has an unhealthy lifestyle and diet will die early. These are the laws within Allāh’s creation because the creation of Allāh operates through cause and effect mechanisms. These cause and effect mechanisms incorporate the effects of increase and decrease (in lifespan and sustenance) just as the faith and righteous deeds are the causes of increase of faith and sins and disobedience are the causes of decrease of faith. So even though the precise state of faith at the point of death is determined, this does not negate increase and decrease in between, until a person reaches the state in which he dies, according to Allāh’s qaḍāʾ and qadar.
In a similar manner, a person may have periods of healthy living and unhealthy living, and his or her behaviour and lifestyle choices will lead to the slowing down or hastening of the ageing process. However, the point at which he or she dies is known and will not be escaped. The change (increase or decrease) can arise, because Allāh has created His creation through ways and means (asbāb) that are tied to effects, or put another way, interconnected cause-effect mechanisms, and through these mechanisms does Allāh make to take place in His creation, that which He knows and wrote down in the Preserved Tablet.
Thus, just as one is urged to take the legislated ways and means with respect to faith and righteous actions, then likewise, one is urged to take the ways and means of increasing lifespan and sustenance.