Continuing the previous answers, I must say that according to the Shiite narrations , Imam Ali, the wife of Fatima( peace be upon her) bathed and shrouded her at night and buried her in the same midnight. So what you said is wrong.
But as for the continuation of the question you asked: How can anyone know the time of his death?
On the other hand, God says about this question: "And no one knows what he will gain tomorrow, and no one knows in what land he will die. "God is All-Knowing, All-Aware."
On the other hand, we read in many histories and narrations that the pure Imams (as) and even some of the saints other than the Imams knew of their deaths or stated their burial place.
Therefore, in the sum of these two issues and the apparent conflict that exists, we must say that awareness of some of these matters in the form of general knowledge - that is, through divine teaching - has no contradiction with assigning their detailed knowledge to the pure essence of God, and as we have said This conciseness is not inherent and independent, but has a transcendental and didactic aspect and is through divine teaching, to the extent that God wills and deems fit.
So the general rule in this case is not knowing the time of death, but exceptionally sometimes some people who have tried to purify the soul and cultivate the soul and are steadfast in the service of God. Like the late Sheikh Morteza Taleghani, Hakim Hidaji, the late Ayatollah Hojjat Kuh-e Kamraei, the father of Ayatollah Araki, Mirza Mahmoud Shaykh al-Islam, Ayatollah Shahaabadi, Ayatollah Seyyed Ahmad Khansari, etc. are aware of the divine teachings from the time of their death.