1- "He had to do it." (obligation)
This sentence is easy to understand for me. It is the past form of "have to" to refer to the obligation in the past, although we don't know for sure he did it or not.
2- He had to have done it. (obligation or probability????)
For some time, I have been thinking the meaning of it, and how it differs from "He had to do it."
And as far as I could understand, it seemed to have the same meaning with: It couldn't have been done by anybody but him.
However, the more I read the more confused I got, because some people say the 2nd sentence is for deduction about the past, not for obligation about the past just like "must have done" is used for deduction about the past, while some others say the 2nd sentence is almost the same as the 1st sentence in meaning with some subtle differences, but then the 2nd one also refers to the "obligation in the past" rather than "deduction in the past".
I wonder if anybody would be so kind as to explain this obscurity?