Early Irish immigrants to the U.S. brought the tradition of making a jack-o’-lantern at Halloween. According to Irish folklore, Jack was a blacksmith who had tricked the devil on several occasions. As the story goes, when Jack died, he was denied entrance into both heaven and hell. When the devil turned him away, he gave Jack a burning ember.
Jack hollowed out a turnip to carry the ember and give him light. The Irish remembered this story each year by carving scary faces on turnips and placing a burning piece of coal inside. However, when the Irish immigrated to the U.S., they discovered that pumpkins were more readily available and made better jack-o’-lanterns than turnips. Eventually, candles replaced the burning coals.
And this could be total BS. It may be neither lore nor a legend. But it makes a good story.