‘Why did’ is by far the most likely but ‘why had’ is possible.
A. He’d quit school by then. (He quit school at a time in the past, which affected some later time but still in our past)
B. Why’d he done that? (It’s a bit repetitive, since you could just ask ‘Why?’. But it’s not ambiguous since ‘why did’ isn’t possible here.)