[This question was originally asked on www.reddit.com/r/askscience on Jan 17, 2013]
The main reason is that our body maintains a multitude of barriers that largely prevent bacteria and other microorganisms from gaining entry. The first and most obvious of these barriers is the skin, but there are also similar barriers along all of your mucosal surfaces (gut, ear, genital tract etc). These barriers consist of cells that are knit together incredibly tightly (google: tight junction), and they also secrete compounds that deter bacteria.
For instance, in your gut, there are trillions of bacteria (more than there are human cells in your body), but the cells lining the gut secrete a thick layer of mucous that keeps bacteria at bay, and also produce things called “anti-microbial peptides” that kill bacteria that wander too close.
Now, these barriers aren’t perfect, and sometimes there’s damage or we get infected with a microbe that knows how to circumvent these barriers, and that’s where our immune system kicks in. Our immune system has evolved to detect the presence of microbes in locations that they are not supposed to be, and then moves in to try to kill them.
These barriers are not static, they are active, and require a lot of effort to maintain. When we die, the cells that keep up those barriers die, and the barriers break down. This allows microbes to get to places that they wouldn’t otherwise, and when we’re dead, our immune system is no longer able to respond. And of course, once those bacteria get to work, the barriers are further weakened, and the process accelerates.