Personal pronouns are ambiguous
Like in English there is no rule to whom a personal pronoun refers to. So the example sentence where the genders are the same
Der Mann jagt den Hund. Er fällt in ein Loch.
it is highly ambiguous. It is the man, or the dog who may have fallen into the pit - we can't say who.
Gender matters
It would be easy to resolve if we had a different gender:
Das Kind jagt den Hund. Es fällt in ein Loch.
Add context
(1) Der Mann jagt den Hund. Er fällt in ein Loch. Der Hund entkommt.
(2) Der Mann jagt den Hund. Er fällt in ein Loch. Er ruft um Hilfe.
(3) Der Mann jagt den Hund. Er fällt in ein Loch. Der Mann holt ihn heraus.
Note that in (1) we need to mention the dog again. It would not work to use a pronoun for the dog excaping because it would then refer to the same subject, the man, in the refernced first sentence like it is in (2). Another example of when we need to name the subject - even though context would make it clear - is given in (3).
Use conjunctions or relative clauses
In case the gender is the same we use relative clauses or conjunctions rather than personal pronouns to avoid confusion:
Der Mann jagt den Hund, der in ein Loch fällt.
Der Mann jagt den Hund und fällt in ein Loch.
Both examples are now unambiguous.