Urban legend lovers and conspiracy theorists love the idea of 18th-century folk using cages to keep possible vampires and zombies in the graves. Obviously, that's not true. Some people may have thought that, but most people wanted to keep people out of the graves rather than cryptids in.
Body snatching was a near epidemic back in the 18th century. It was an easy crime to commit without getting caught and the payoff was worth it. Weirdly enough, the body snatchers were not the common criminal-type that you might have thought they were...
Medical schools and doctors frequently hired bodysnatchers to steal body parts of recently deceased people. This was the best way for them to study human anatomy since many people weren't interested in donating their bodies to science back in the day.
Funny enough, police departments usually turned a blind eye to grave robberies due to the fact that it was for the "better good." Bodies would be transported all over the world by the robbers.
Once people caught onto the crimes, they started taking extra steps to protect the body of their loved one. The rich usually opted for mausoleums or heavy tombstones, but the poor couldn't do that.
The mortsafe was invented as a cost-effective way to keep the integrity of the deceased. Cemeteries everywhere were riddled with them, which made it look like a post-apocalyptic world.