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.
No one knows the exact time or place of his death; Allah, The Exalted, Says (what means): {Indeed, Allah [alone] has knowledge of the Hour and sends down the rain and knows what is in the wombs. And no soul perceives what it will earn tomorrow, and no soul perceives in what land it will die. Indeed, Allah is Knowing and Acquainted.} [Quran 31:34] However, a person may feel or expect the approach of death either because of a vision (dream) he sees or something of the sort, and his premonition may come true. ‘Umar had a dream and interpreted it as the approach of his death, and it came true when Abu Lu’lu’ah Al-Majoosi, may Allaah curse him, stabbed him. It was narrated on the authority of Ma‘daan ibn Abu Talhah that ‘Umar ibn Al-Khattaab both, delivered a sermon on Friday and spoke about the Prophet, sallallaahu ‘alayhi wa sallam, and Abu Bakr then said, "I saw in a dream that a rooster pecked me three times, and I take it to mean that my death is imminent…" [Muslim]
Similarly, the Companion ‘Abdullaah ibn Haraam felt prior to the Battle of Uhud that he would be martyred in that battle. He informed his son, Jaabir, of it and told him what should be done (after his death), and his premonition came true. It was narrated on the authority of Jaabir that he said: "When the time of the Battle of Uhud approached, my father called me at night and said, ‘I think that I will be among the first to be killed from the Companions of the Prophet, sallallaahu ‘alayhi wa sallam. I do not leave anyone behind me dearer to me than you except the Messenger of Allah, sallallaahu ‘alayhi wa sallam. I owe some debt, so repay it, and take care of your sisters.’ In the morning, he was the first to be killed..." [Al-Bukhaari]
Similarly, Az-Zubayr ibn Al-‘Awwaam felt before the Battle of Al-Jamal (the Camel) that he would be killed in that battle, and it came true. It was reported on the authority of ‘Abdullaah ibn Az-Zubayr that he said: "When Az-Zubayr got ready to fight in the Battle of Al-Jamal, he called me and said: ‘My son, whoever is killed today will be either a wrongdoer or a wronged one, and I expect that I shall be killed as a wronged one today…" [Al-Bukhaari]
It was also narrated in Sunan Sa‘eed ibn Mansoor on the authority of Taariq ibn Shihaab that he said: "Sa‘d ibn ‘Ubayd delivered a speech at Qaadisiyyah and said: ‘We are going to meet the enemy tomorrow, Allah willing, and I expect that I shall be martyred. So do not take off my clothes except for my Khuff (leather socks).’" [End of quote]
We did not find any reference to the words that you attributed to Abu Haamid Al-Ghazaali and Allah knows best. A Muslim is required to strive in doing good deeds and be prepared to meet Allah, The Exalted, in all cases and at all times, regardless of whether or not he felt the approach of his death. It was narrated on the authority of ‘Abdullaah ibn ‘Umar that he said: "The Prophet, sallallaahu ‘alayhi wa sallam, took me by the shoulder and said: “Be in this worldly life as if you were a stranger or a wayfarer.” Ibn ‘Umar used to say, “In the evening, do not expect [to live until] the morning, and in the morning, do not expect [to live until] the evening. Make full use of your health before times of sickness, and make full use of your life before your death." [Al-Bukhaari]
Allah Knows best.