Only by being forced to defend an idea against the doubts and contrasting views of others does one really discover the value of that idea.
What is the function of "does" in that sentence?
Only by being forced to defend an idea against the doubts and contrasting views of others does one really discover the value of that idea.
What is the function of "does" in that sentence?
It's to support subject/verb inversion (as in "neither do I" or "so do we"). So 'does' is standing in for the main verb, 'discover' because modern English avoids inverting except with auxiliary verbs such as do, can, will. Without 'does', you'd have to say 'Only by ... views of others DISCOVERS ONE ...' which isn't done in modern English.
Only by being forced to defend an idea against the doubts and contrasting views of others does one really discover the value of that idea.
This sentence has certain properties which mean that there must be subject-auxiliary inversion in the main clause for the sentence to be grammatical. (This just means that the auxiliary verb and the subject change places.) These conditions are:
In the original sentence, the adjunct is a preposition phrase headed by a preposition is: by being forced to defend an idea against the doubts and contrasting views of others. This has been moved to the front of the clause and is being pre-modified by the adverb only.
Because, and only because, all four of these conditions are met, the subject and auxiliary verb in the main matrix clause must be inverted. Notice that this is not merely a case of negative adverb pre-posing. It is not quite the same as sentences such as:
In the sentence above, the adverb never has been moved from the post auxiliary position to the beginning of the clause, it is not modifying an adjunct, it is the adjunct and it modifies the whole main clause. In the original poster's sentence, only modifies the preposition phrase adjunct "by being forced to defend an idea against the doubts and contrasting views of others". If we try to pre-modify a main clause with only, the result will not be grammatical.
Or, alternatively we will find that only has a different meaning serving as a discourse marker and we won't see any subject auxiliary inversion:
Here are some examples of bona fide subject auxiliary inversion with only:
If we don't have inversion here the sentences won't be grammatical:
In the Original Poster's sentence the main clause is in the present simple. If there was no inversion we would expect it to read:
Because of the pre-posing of the only-preposition phrase we need subject auxiliary inversion. You will notice that in the main clause above there is no auxiliary verb, because it uses the present simple. When we need an auxiliary in such cases we use the dummy auxiliary DO. This gives us the necessary auxiliary verb to invert with the subject:
In short then the function of does here is to allow subject auxiliary inversion. This inversion is necessary because of the fronting of a preposition phrase adjunct pre-modified by only.