The term, Graveyard Shift, for a late-night work shift dates to around the turn of the 20th century. It is a reference to the desolation and loneliness of late-night work. The term gets it start in nautical circles with the form graveyard watch. From G. Tisdale’s book; Three Years Behind The Guns of 1895: "I am to stand the first lookout in the graveyard watch."
1907 sees the move to dry land and shift replaces watch. From Collier’s Magazine of 26 January of that year: From the saloons came the clink of the chips. For it was the “graveyard gamblers” shift...The small hours of the morning, when the carelessly speculative world is asleep, are theirs.
And a year later, in the Saturday Evening Post of 7 November 1908, we see: A month later he and his fellows went on the “graveyard” shift. “Graveyard” is the interval between twelve, midnight, and eight in the morning.
The story that is just that a "story" with no facts to back it up. "England is old and small and the local folks started running out of places to bury people. So they would dig up coffins and would take the bones to a "bone-house" and reuse the grave When reopening these coffins, 1 out of 25 coffins were found to have scratch marks on the inside and they realized they had been burying people alive. So they would tie a string on the wrist of the corpse, lead it through the coffin and up through the ground and tie it to a bell. Someone would have to sit out in the graveyard all night (the "graveyard shift") to listen for the bell; thus, someone could be "saved by the bell" or was considered a "dead ringer."
The term does not date to the 16th century as is claimed in the internet lore titled Life in the 1500s. Nor does it have anything to do with men stationed in graveyards listening for those accidentally buried alive to ring bells in their coffins to alert others that they are alive, nor is it a reference to medical students robbing graves in search of cadavers. Graveyards did have guards to watch for and deter grave robbers.