Walt Whitman was a poet who seemed to write in many different genres (some have deemed him a Realist, a Romantic and a Transcendentalist). Renowned for his use of nature and open sexually explicit texts, Whitman's reoccurring theme of death was a part of his realistic look at the circle of life.
As a Romantic, his poetry used many images of nature in different states of life (new life to decay). As a realist, Whitman did not attempt to sway life or change it for the better; instead, he illustrated life as it was (meaning sexual and obscene at times). Although criticized for his work, Whitman refused to change his ideology behind why life was as it was.
Given that death was (and still is) a natural part of life, Whitman showed readers what it meant to die. In some poems, he promised a sort of rebirth, while in others, he refused to mask the truth surrounding it. For example, in "Adieu to a Soldier," Whitman shows the reality of war and the consequences of it ("Red battles with their slaughter").
In the end, Whitman's recurrent themes of death simply sopke to life as it was. Man, and nature, will die. No critic could stop that (in the same way that they could not stop Whitman). Therefore, Whitman chose to celebrate and detail death.