Know that funerals are a lesson to the man possessed of insight, and a reminder and a counsel to all save the people of heedlessness. For these latter are increased only in hardness of heart by witnessing them, as they imagine that for all time they will be watching the funerals of others, and never reckon that they themselves must needs be carried in a funeral cortege. Even if they do so reckon, they do not deem this to be something near at hand. They do not consider that those who are carried now in funeral processions thought likewise. Vain, then, are their imaginings, and soon their allotted lifespans will be done.
Therefore let no bondsman watch a funeral without considering that he himself is the one being borne aloft, for so he will be before long: on the morrow, or on the day that follows: it is as if the event had already occurred.[...]
Such, then, was their fear of death. But nowadays never do you see a group of people attending a funeral without the majority of them laughing and enjoying themselves, speaking of nothing but the inheritance and of what [the deceased] has bequeathed to his heirs; the sole though in the mind of his friends and relatives being of the devices by which they might obtain some share in his legacy. Not a single one of them (save those who God wills) meditates upon his own funeral and upon how he shall be when he himself is carried in a funeral cortege. The sole reason for this is the hardness which has afflicted people's heart through their many acts of disobedience and sin, whereby we have come to forget God (Exalted is He!) and the Last Day, and the terrors which lie before us. We have taken to playfulness and neglect, and to busying ourselves with that which is of no concern to us. We pray God (Exalted is He!) to rouse us from this heedlessness! For truly, the best of states in those who attend funerals is that they should weep for the deceased; moreover, if they had any understanding they would weep for themselves rather than for him.-al-Ghazali in The Remembrance of Death and the Afterlife. Translated by T. J. Winter (Islamic Texts Society, 1989), 97-98.
Part of the quote was copied from here.