The idea of fruit bestowing immortality, or at least longevity, is a common one in mythology and folklore. In Norse mythology, the gods are said to eat apples that restore their youth. The fruit can’t entirely prevent them from dying, as shown with Ragnarok and Baldur with the mistletoe, but they presumably don’t die of old age. The keeper of the apples is Idun, a goddess sometimes said to be related to elves or dwarves. One poem refers to her as a daughter of Ivaldi, also the father of the dwarves who made magical items for the Aesir. Her husband is Bragi, god of poetry and son of Odin.
The most prominent appearance of Idun in mythology is the story where she’s kidnapped by the giant Thiazi, father to the wintry goddess Skadi. The Aesir start to grow old without the apples, so Loki has to get her back, which he does by transforming himself into a falcon and her to a nut, which he carries to Asgard in his beak. I don’t know that it’s ever specified where Idun gets the apples, or why no one else is able to access them.
In Greek mythology, there are the golden apples of the Hesperides, a wedding present from Gaea to Zeus and Hera. The Queen of Olympus had them tended by nymphs on an island in the far west of the known world.
They’re guarded by the serpent Ladon, and some sources claim that they can make those who eat them immortal. I don’t know if this was originally part of the myth or due to its confusion with similar stories, though. I’m not sure it ever comes up anyway, since the few apples that Hercules takes to fulfill one of his labors are returned to the garden. The golden apple that Eris uses to indirectly cause the Trojan War is sometimes said to be from there as well.
The island of Avalon that’s supposed to be the resting place of King Arthur is associated with apples, located to the west of Europe, and attended by several sisters with magic powers.
There’s probably a connection there.
In the Bible, there’s the Tree of Life, which could apparently make humans live forever. After Adam and Eve eat the forbidden fruit that grants them knowledge of good and evil, God is afraid that they’ll eat from this tree as well.
It seems a bit inconsistent, as He apparently never forbade the fruit of that one. Maybe he wouldn’t have minded if they’d lived forever as long as they remained stupid. Some interpretations say that they were originally meant to be immortal anyway, which makes me wonder what the point of the Tree of Life was. Regardless, there will apparently be a few such trees in the New Jerusalem described in the Book of Revelation. The fruit of either tree is never described, but the similarity to the garden of the Hesperides has led the forbidden fruit to be associated with apples. It also doesn’t hurt that the Latin word malus can mean both “apple” and “evil.” This post, which I found when looking for information on immortality-granting fruit, proposes that apples were associated with eternal life because they keep well and can be eaten in cold weather. I’m sure there’s something in that, but at the same time I don’t know for sure that all of the apples from mythology originally WERE apples. Wikipedia claims that apples weren’t even known in Scandinavia in the era in which the myth of Idun would have originated. I’ve seen some suggestions that golden apples might have actually been oranges. In Chinese mythology, the fruit that grants long life is a peach.
So it might not be apples per se that are associated with immortality, but fruit in general.