Specific uses of perfect constructions can only be understood by considering the discourse context in which they are used.
Here's your sentence in its context:
A repair shop employee [...] also testified that, while the repair shop had no record of Berardelli picking up the gun, the gun was not in the shop nor had it been sold, as unclaimed guns sometimes were.
The day after he was arrested, Vanzetti had told Katzmann that he carried the gun to protect his fish cart. He said that he had bought the gun in Boston four or five years earlier—although he could not remember where—and had paid eighteen or nineteen dollars for it. Now in court he testified that he had actually bought the gun seven months earlier [...]
Vanzetti’s statement at the time of his arrest is cast in the past perfect because the context—the Reference Time (RT) to which all the events of this chapter are related—is the trial, several weeks after the arrest. The author is not at this point narrating the arrest but providing background for his narrative of the trial. Here's the first part of the excerpt with the simple pasts marked RT, indicating they speak of events occurring at RT, and the past perfects marked →RT, indicating they speak of events occurring before RT as background to the events at RT:
A repair shop employee [...] also testifiedRT that, while the repair shop hadRT no record of Berardelli picking up the gun, the gun wasRT not in the shop nor had it been sold→RT, as unclaimed guns sometimes were.
The day after he was arrested, Vanzetti had told→RT Katzmann ...
But note what immediately follows this. The author treats the timeframe established by the past perfect had told as a secondary RT (I mark this as RT′) and proceeds to narrate events at the time of the arrest with simple pasts , employing the past perfect (→RT′) to bring in events before that time. The original past perfect has effected a time shift:
... that he carriedRT′ the gun to protect his fish cart. He saidRT′ that he had bought→RT′ the gun in Boston four or five years earlier—although he could not rememberRT′ where—and had paid→RT′ eighteen or nineteen dollars for it.
After this very brief narrative the author explicitly returns to his primary RT, where the constructions resume their original time reference:
Now in court he testifiedRT that he had actually bought→RT the gun seven months earlier [...]
Everything between the testimony of the repair-shop employee and Vanzetti’s testimony is background, introduced as such by a past perfect—which also provides an ‘anchor’ permitting the author to revert to his original narrative.
This is treated in more detail at What is the perfect, and how should I use it?, especially §4. When and how should I use the perfect?. The ‘rule of thumb’ offered there is
☛ Use perfect constructions to introduce prior eventualities as context for the current discussion.