Several morals are at the heart of Tolstoy's novella, but the one I'll discuss is the author's message that the material world is basically illusory and meaningless in the long run.
Ivan Ilyich is an ordinary man, and a not a bad man at all. He has led a standard, conventional existence: marrying, having children, and finding success in his working life. This ordinariness is what the author tells us somehow makes his fate "all the more terrible." When a serious disease strikes Ivan Ilyich, he reacts as if an absolutely inexplicable thing has happened. He (like most people, in fact) has never grasped the reality of death. And those around him are the same way. His wife and especially his daughter are remote from the trauma of his illness. None of the family have ever given a thought to non-material concerns. The only person who appears to have empathy for Ivan Ilyich is his servant Gerasim, a young man of rural background. Tolstoy's point, the subtext of Gerasim's difference from the others, is probably that laboring people, because they are not consumed with wealth and possessions, have not lost their spirituality and their awareness of the realities of suffering and death, in the way that middle- and upper-class people, concerned with the material world, have done.
With illness, constant pain and the inevitability of death, Ivan Ilyich's entire world has collapsed. It is not until his final three days when he screams continuously in agony that he becomes aware that the focus of his life has somehow been in error, or that at least, he has missed the main point of existence which, in Tolstoy's moral, is the reality of death and the primacy of the spiritual over the material world.