According to 'America's Popular Proverbs and Sayings' by Gregory Titelman, this expression was first found as a Welsh folk proverb in 1866: 'Eat an apple going to bed, and you'll keep the doctor from earning his bread'.
However, I wonder if it it's root isn't further back in time, and that the expression is not simply saying that apples/fruit keep you healthy, but alluding to the apple as a symbol. For example, in ancient Irish tradition the apple symbolized immortality, and many traditions have believed the apple to be a symbol of love and fertility, even the preferred food of the gods - if you cut an apple in half across the middle you'll see that the core forms the shape of a five pointed star/pentagon - a shape that has been revered for millennia as having spiritual qualities.
More about apples:
Pythagoreans, in ancient Greece, gave apple as gifts because of their pentagon shaped core.
Traditional Christianity often refers to the fruit of the Tree of Knowledge as being an apple.
Apples have long been associated with divination: these are some of the many traditions:
Bobbing for apples (trying to retrieve an apple using only ones mouth from a tub of water) was originally a boys game - the girls prepared the apples and the boys would bob for them, the apple that each boy retrieved indicated who they would marry.
Peel an apple in one piece, throw the peel over your shoulder and the shape that the peel falls in indicates whether the answer to the question should be yes or no.
If your question is about love, take a pip from an apple, state the name of your loved one, throw the pip in the fire, and if it pops it indicates that the love is reciprocated!
Kenn Nesbitt is new Children's Poet Laureate(Jun 12 2013) Kenn Nesbitt has been named the new Children's Poet Laureate: Consultant in Children's Poetry to the Poetry Foundation, which noted that the two-year position...