In the quoted line, Whitman uses a metaphor of "beautiful uncut hair of graves" to compare it with the grass that grows in the graveyard in an untidy fashion. Here, the "grass" stands for both life and death. It does not contrast them but establishes a connection between them.