As so often, neither is wrong in itself. The choice would depend on the context and personal preference.
It helps if you replace had with needed, which means the same thing - to avoid had had.
Mary said to Gail: I needed to finish the work (before lunch).
Gail remarked soon afterwards: She said she needed to finish the work (before lunch).
In this immediate situation, it's idiomatic to stick with the past tense. It's not wrong to use the past perfect although most people probably wouldn't.
But if months later there was a police investigation into Mary's disappearance and Gail was asked whether Mary might have said anything that would assist the investigation. Gail would probably respond:
She said that she had needed to finish the work before lunch that day.
In this context, the speaker is looking back on past events and preferring the past perfect tense. Once again, many people would simply use the past tense.
There is no right of wrong version.
Using the past perfect tense serves to emphasise that one event took place prior to another. The choice is personal and guided by the context.