Allah Almighty says, “…nor does any one know in what land he is to die.” (Luqman: 34) This verse means that no one can know where or when he is to die because these are matters that only Allah knows. However, a man’s feeling that he is about to deliver his soul does not mean that he knows where or when he will die, and reality confirms that no one can foresee this.
Additionally, a man’s feeling that he is near to his death is something that Allah may inspire to some of His servants at the time when they are about to die, and not before that. This can happen through a vision. It often happens that a man feels that he will die after a while but this does not really take place.
Dr. Muhammad Abu Laylah, professor of Islamic Studies & Comparative Religions at Al-Azhar Univ. states: “Revelation (wahi in Arabic) is only given to a Prophet or a Messenger of Allah. But inspiration (ilham in Arabic) can be given to some people, revealing to them some of the hidden things, filling them with premonition about their death or something bad to happen.
Some people may see in vision things, which later become true. There is no contradiction here at all. It is rather a proof that Allah is managing the affairs of His people and is Close to them. This feeling alone can be considered as a proof that Allah is there and that He is Near to man. Allah says: “We verily created a man and We know what his soul whispereth to him, and We are nearer to him than his jugular vein.” (Qaf: 16)
In the same surah, He says: “(And unto the evil doer it is said): Thou wast in heedlessness of this. Now We have removed from thee thy covering, and piercing is thy sight this day.” (Qaf: 22)
This is a special gift or warning to man, but the general rule about death and life in Islam can be seen in the following Qur’anic verse: “Lo! Allah! With Him is knowledge of the Hour. He sendeth down the rain, and knoweth that which is in the wombs. No soul knoweth what it will earn tomorrow, and no soul knoweth in what land it will die. Lo! Allah is Knower, Aware.” (Luqman: 34)
Therefore, what you have referred to in your question can be better understood in the light of these facts. Communication between the dead and the living human beings in night visions is possible from the Islamic point of view. The dead people are not finished, but they are living in another sort of life, which we call Al-Barzakh.”