Along with Biblical expressions, proverbs form the bulk of the very earliest phrases that have existed in English since the language was first recorded on paper. ‘A penny for your thoughts’ is one of the few that is neither of the above but which is of the same vintage.
The first known use of it is by Sir Thomas More in A Treatyce upon the last thynges, circa 1535:
In such wise yt not wtoute som note & reproch of suche vagaraunte mind, other folk sodainly say to them: a peny for your thought.
(A rough paraphrase of the above is “when people notice that someone appears disengaged and wish them to rejoin the conversation they ask ‘a penny for your thoughts’.”)
The expression became so well used that it was often shortened to ‘a penny for them’ or even just ‘penny’, as in H. G. Wells’ novel Love & Mr. Lewisham, 1900:
‘Penny,’ she said after an interval. Lewisham started and looked up. ‘Eh?’.
It is less common in the 21st century and more used by the older generation than the young.
See also: the List of Proverbs.