First Example
In the following example that you provided, your use of "they" is correct. You can't omit it.
Students were absentminded, thinking what to do when they get home early.
You can not say the following:
Students were absentminded, thinking what to do when get home early.
This is because it is not implied who you are talking about in the second part of the sentence.
Second Example
This sentence, as you would probably expect, is correct:
If they are not doing homework, they get lazy.
However, it is also perfectly acceptable to say:
If not doing homework, they get lazy.
This is because it is implied who you are talking about in the second part of the sentence.
Note
You said that it was perfectly acceptable to say this:
When not a teacher, he lived a life of a monk.
This is correct.
However, in English it does read better if you say (formally):
When he was not a teacher, he lived the life of a monk.
Or (informally):
When he wasn't a teacher, he lived the life of a monk.
As an English speaker myself, my preferred choice would be the latter.
Conclusion
It is okay to omit "they" from the first part of the sentence as long as you make sure that the reader knows who you are writing about (he, she, they, we and so on) after they have read the second part of the sentence.