I agree with JTT. It's just poor English; must be something new they're teaching in school. The phrase 'had had' is just a written stutter and poor practice.
You can 'have had' or 'has had', but never had had.
"I realized that I had it in my pocket all along."
Accomplishes the same thing, but in a clearer manner. It's in my pocket regardless of the time I put it there, which was earlier today, which can be construed by the word 'realized' and confirmed by 'all along'. It's there now, since nothing in the sentence ever stated that I have removed it, it has been in there a while, and will continue to be in there until I remove it.
If you want to convey the past, use have or has with had, or just plain had will do.