A coffin is a box that a corpse is put in, and buried in. A grave is a place of burial for a dead body. Grave can also mean serious, so "grave matter" means "serious matter". This joke is playing on the word "grave" and its different meanings.
Digging a hole for a coffin is a grave matter .