This is a light-hearted expression, used to ask someone what they are thinking about; and usually when the 'someone' has fallen unexpectedly silent or pensive.
Don't let the reference to 'penny' fool you into thinking along the lines, if his thoughts are only worth a penny, they are deemed to be of low value, little importance, trivial.
The first recorded reference to this saying goes back to 1522, when Sir Thomas More wrote (in 'Four Last Things'): 'It often happeth, that the very face sheweth* the mind walking a pilgrimage, in such wise that other folk sodainly** say to them a penny for your thought.'"; and was so noted in 1546, in a book later re-titled, The Proverbs of John Heywood,
So, with inflation, then by today's standards, "£25 for your thoughts." Satisfying one's curiosity has never been cheap!
* archaic : sheweth = showeth = show/shows
** (archaic - meaning 'suddenly', 'unexpectedly'