It all started with the plague: The origins of “six feet under” come from a 1665 outbreak in England. As the disease swept the country, the mayor of London literally laid down the law about how to deal with the bodies to avoid further infections. Among his specifications—made in “Orders Conceived and Published by the Lord Major and Aldermen of the City of London, Concerning the Infection of the Plague”—was that “all the graves shall be at least six feet deep.”
The law eventually fell out of favor both in England and its colonies. Modern American burial laws vary from state to state, though many states simply require a minimum of 18 inches of soil on top of the casket or burial vault (or two feet of soil if the body is not enclosed in anything). Given an 18-inch dirt buffer and the height of the average casket (which, based on the ones I just looked at, appears to be approximately 30 inches), a grave as shallow as four feet would be fine.
A typical modern burial involves a body pumped full of chemical preservatives sealed inside a sturdy metal casket, which is itself sealed inside a steel or cement burial vault. It’s less of a hospitable environment for microbes than the grave used to be. For untypical burials, though—where the body isn’t embalmed, a vault isn’t used, or the casket is wood instead of metal or is foregone entirely—even these less strict burial standards provide a measure of safety and comfort. Without any protection, and subjected to a few years of soil erosion, the bones of the dearly departed could inconveniently and unexpectedly surface or get too close to the living, scaring people and acting as disease vectors. The minimum depth helps keep the dead down where they belong.