The teachers have had some problems deciding when they should return the final papers to the students.
My questions are:
1. Is ...deciding when they should return the final papers .. a gerund phrase?
Historically, the type of construction you are asking about relates to a construction in which "deciding when . . ." would function as the object of a preposition, typically "in":
The teachers have had some problems in deciding when they should return the final papers to the students.
If that were the construction in play, then "deciding" would be what most ESL teachers incorrectly call a gerund. And if you analyze your sentence as containing an omitted preposition before "deciding," then you could say that is the construction in play.
That "deciding" is not, even in the prepositional construction, a gerund may be seen by considering that a gerund is a verbal noun and nouns do not have direct objects. Thus, we should not be able to say, e.g., "They have had some problems in deciding this matter." Here is the related gerund construction:
They have had some problems in the deciding of this matter.
Now, it would be ungrammatical to say,
*[strike]They have had some problems the deciding of this matter[/strike]. So the gerund analysis doesn't work, technically. However, if you go in for the omitted-preposition analysis, you could say that "deciding . . ." is a nominal participial phrase: a participial verb phrase that functions as a substantive.
Another analysis that is possible is one on which the "deciding" phrase is an Integrated Participial Clause (De Smet, 2013*), a participial phrase that does not function as a substantive but as an obligatory adjunct or complement in the construction beginning with "had some problems . . . ."
One piece of evidence favoring the closer "integration" of these participial clauses, as opposed to other participial adjuncts, is that elements within such participial phrases can easily be relativized (in relative clauses), whereas that is not possible with participial adjuncts not so "integrated." Consider these sentences:
There is a matter that they have had some problems deciding _.
?* This is the matter that they sat at the table deciding _.
2. Why do we use the subject + verb formation after when.
Subject-auxiliary inversion is used in root questions, not in embedded questions. The "when"-clause following "deciding" is an embedded question.
They should return them then.
When should they return them?
[strike]
*When they should return them?[/strike]
I wonder when they should return them.
[strike]*I wonder when should they return them.[/strike]
They decided when they should return them.
[strike]*They decided when should they return them.[/strike]
------------------------------------------
*De Smet, H. (2013).
Spreading patterns: Diffusional change in the English system of complementation. Oxford: Oxford University Press.