No, contrary to some reports, these are not to trap zombies or vampires as they rose from their grave, but rather to stymie grave robbers stealing corpses for sale to medical students and anatomists as legitimate sources in the form of convicted criminals put to death could not keep up with demand.
Known as mortsafes, these were quite common in Scotland in the 19th century before legislation simplified the process of procuring bodies legally.
Bottom photo via Kim Traynor of Greyfriars Kirk via Wikimedia Commons
Via Hoax-Slayer.