That detail or incident reminds one of another story, as in So he went without supper, but thereby hangs a tale. This expression, embodying the pun on tail and tale, was used by Shakespeare in at least four of his plays and presumably was well known before that. [1500s]
The American Heritage® Idioms Dictionary Copyright © 2002, 2001, 1995 by Houghton Mifflin Harcourt Publishing Company. Published by Houghton Mifflin Harcourt Publishing Company.