The phrase is a rhetorical question. It’s used to express bemusement or vexation, or gloating when someone turns the tables on someone else. It can also be directed mockingly at someone who has received surprising information, ridiculing the situation, and has overtones of challenge and mild disrespect.
It has been suggested that the phrase originated in World War I. It certainly became widely known during that war, and its popularity may have been influenced by the various “apple” grenades and mortars used at that time.
The phrase was mentioned in a book called History of Company A, 307th Engineer Regiment, 82d Division, United States Army from 1919. It is found in the part of the document called “Company Reminisces,” a collection of recollections, sayings, and inside jokes from the referenced Army unit.
Then at some point in the late 1920s, it started to be used among college students, and was included in an article in the Princeton Alumni Weekly newspaper from April 1928. After WWII there is again a dip in usage, followed by a steady rise beginning in the late 1950s, concurrent with the rise of Beat poetry.
But there is no real evidence for its origin, military or otherwise, though it has been found in print as early as 1895.
One sensible theory is that it was regional or family slang before World War I. During the two world wars, it would have been shared and become popular among men from different regions and different countries. When the soldiers returned home from the conflicts, they spread the phrase among civilians. After WWII, when writing became more realistic and informal, the phrase would have appeared in print much more often.
That theory does sound sensible and perhaps that’s how it happened. But I want to know why the phrase isn’t, for example, “how do you like them peaches?”