The answer to the question of why he had to marry again... So what is the grammatical function

The grammatical function of "why he had to marry again" is a noun clause functioning as the direct object of the verb "answer."