Good question. This is often a confusing introduction. But it's actually pretty logical when you establish that the narrator is a fictional character.
A custom house was a place where taxes were paid, a place of government business. The narrator, working in Salem's custom house and writing this around 1850, tells of finding some papers, documented by Jonathan Pue who worked in the custom house 100 years before (around 1750). Pue's work chronicles the story of the events of Hester Prynne which occurred about 100 years prior to Pue's time (around 1640).
The nameless narrator is quite similar to Hawthorne. Both worked in a custom house and both had Puritan ancestors. But the narrator is a fictional creation. The text of The Scarlet Letterand the Custom-House introduction are both fictional creations of Hawthorne. So just consider the whole thing, cover to cover, as fiction (even though it is based on the idea that it is all historical.)
Hawthorne wants to set up this story as one historian commenting on a prior historian; the narrator (in 1850) finds historical documents written by Jonathan Pue (in 1750 or so) concerning the historical record of Hester Prynne's social indictment (which occurred in 1640).
Doing it this way, the "Custom-House" introduction is presented as an historical document itself or a retelling of historical documents. This structure of a narrator in 1850 telling of some documents (written in 1750) about some events which occurred in 1640 signifies the importance of history and the legacies, stories, and moral traditions/evolutions of successive generations.
It's also a well thought out introduction about how historical research works: finding texts from 1750 which are about events in 1640.The Scarlet Letteritself is the "Custom-House" narrator's narrative retelling, his storied version, of Jonathan Pue's account of Hester Prynne. The narrator even foresees generations 100 years after him reading his work. So, the whole thing, cover to cover, is a fictional story, about finding out things from history.