(a) I found it difficult to stop thinking of one little girl.
(b) I hate it when you do that.
Why is it necessary to use "it" in the sample sentences above when the role of the object play (a) gerund, (b) the subordinate clause?
(a) I found it difficult to stop thinking of one little girl.
(b) I hate it when you do that.
Why is it necessary to use "it" in the sample sentences above when the role of the object play (a) gerund, (b) the subordinate clause?
In sentence a, you need the dummy pronoun it, because the direct object with found in this meaning is placed between found and the complement to the object. The normal construction is found + something + difficult, but because the direct object is a whole subclause (to stop thinking of one little girl), that subclause is placed at the end of your main clause. That is why we use the dummy pronoun it between found and difficult to keep the regular order of words. A sentence like this would not be pleasant to read:
I found to stop thinking of one little girl difficult.
So for reasons of readability and comprehensibility, long phrases are often moved to the end of the sentence. However, without the it the sentence would become ungrammatical:
I found difficult to stop thinking of one little girl.
You need the direct object to precede the complement to the object difficult, but because we moved that direct object to the end of the sentence due to its length, you insert the dummy pronoun it:
I found it difficult to stop thinking of one little girl.
Note that the subclause still acts as the actual direct object!
In sentence b, the it can be dropped, but your sentence will then be informal. Have a look at this answer on ELU where the difference between hate it when and hate when is explained.
In your case, when you do that is a direct object. However, because of the when it probably looks like an adverbial complement of time which I am guessing is the reason for the it being put into place. The when does not introduce an adverbial complement. It is the person you in the act of doing that which the speaker hates. It is not something else that he/she hates at the moment of you doing that.