What is the grammatical explanation for when to use "me" or "to me"?
For example: Explain it again to me.
Example: He wrote me a terrible letter.
Ex: She sent a letter to them.
Ex: She sent them a letter
Do we use to + the pronoun when there is an object before the pronoun?
The correct way is as in your sentences.
When the indirect object (me, them) comes first, there is no "to". 2 and 4
When the indirect object comes after the direct object, there is a "to" before the indirect object (to me, to them). 1 and 3