Apples don’t actually have anything to do with Halloween. They, and all the traditions associated with them, are remnants of some of the really old religions that got passed down and combined onto this giant blob of stuff that is now part of Halloween.
Apples have been around for a really long time and therefore have been part of human customs for a really long time. They are one of the many crops that get harvested in the autumn and as such have always been pretty revered for their ability to feed people. Like a lot of the crops harvested, they serve many purposes- we use their skins, their flesh, their juice and their seeds in cooking, fermenting, flavoring meats, and just storing up for winter.
As most of the ancient religions were based on earth elements and the things that support life so apples too are associated with religious customs. I have no doubt that apples were part of even more archaic traditions done at harvest times well before the Roman empire came about but since we don’t have much historical record from that time the first organized mention of apples in religion came around at that time. Specifically, they are associated with the Roman goddess Pomona, the goddess of orchards and harvest.
The festival of Pomona took place every November 1st on the Roman calendar and involved (as with most Roman holidays) a large feast with a bunch of divination rituals thrown in. As the Romans adopted the Celtic traditions of Samhein, the traditions of the festival got mixed in and passed down as part of the package.
So it is that most of the apple-based traditions we do at Halloween time came from those customs associated with Pomona divination rituals. Most specifically, bobbing for apples. This was originally called “ducking” and looked pretty much exactly the same as bobbing for apples does now save that the person who successfully retrieves the apple doesn’t get a prize but rather is foretold to be the first person to marry in the coming year. Another tradition which is no longer practiced called “peeling” involved attempting to peel an apple in one long strand. That peel was then thrown on the floor and the cursive letter formed was said to be the first initial of the person you would marry. (The resulting peeled apples would then be used in all sort of tasty apple-based recipes.)
How, you may wonder, did this mating ritual come to be a kid’s game? Because as these customs were passed down they were most often used in adult party activities. Why? Because “dating” is a relatively new concept and young people didn’t have a lot of opportunities to meet and greet outside of holiday celebrations. So, at adult Halloween parties over the centuries these rituals would be performed. When Halloween became a more kid-centric holiday earlier in the 20th century, bobbing for apples became a game done for prizes at kid’s parties. And so, we now use this rather ancient tradition in modern-day customs thereby retaining the tradition of Halloween being a hodge-podge of rituals and traditions gathered from a variety of sources. Plus, apples are still delicious.