The story
As with the similar phrase put a pin in, popular modern theories suggesting origin in 20thC military use (re-inserting the safety pin into a hand grenade) or using thumbtacks to attach notices to a corkboard, are chronologically impossible. Physical evidence from 18thC books suggests the phrase may derive from the practice of readers inserting sewing pins into the fold near a book's spine to mark a specific passage or page.
Etymology from Wiktionary, CC BY-SA 4.0.