"I pity those who lost their money in gambling."
This is correct.
"I know the first one is correct, but I think there is nothing wrong grammatically with the second sentence."
I'm assuming you are a learner of English. You'll not have heard the second sentence used, so a general rule is: Don't use it. Even saying it once is slightly contaminating your understanding with an error you will have to practice to unlearn.
Aside: If as a learner you see the entire English language left to learn as a pile of coal in front of you which you have to shift, it's enormous - and there's in all of us a temptation to find a certain number of general rules so as to reduce this down to a smaller number. I say, resist this urge: not only ie English firstly too irregular for regular rules to help much; but secondly you'll learn the expressions along the way as you practice - and thirdly, Looking for rules is wasting valuable time when you could be speaking reams of English!
NOTE: personal pronouns like who and whom have case form. The case form for who is the nominative case (often the subject of a sentence); the case form for whom is the objective case, usually a direct object.
CORRECT: I know the girl whom you are talking to.
The relative pronoun "whom" is in the objective case. This means it acts not a subject, for example, but as an object. Who is the other case, the nominative case; it's the one you would use as a subject the sentence. The rule is that the object of a preposition "to" in a prepositional phrase is in the objective case: whom.
I know the girl. You are talking to whom
CORRECT: It was the girl whom her mother punished for stealing money.
For this one, we'll remove the main clause: It was the girl. [this is the main clause; it's and independent clause, which means it can stand on it's own as a sentence.
That leaves the dependent clause: who/whom/that her mother punished for stealing money [If we take out the relative pronouns, we can see if we have a subject and a verb: her mother punished for stealing. There's the verb--punished Now where's the subject? mother. But something is missing. Who? or What? did the mother punish? The girl. The girl is the direct object [she receives the action of the verb] of the verb "punished" and so since "girl" is in the main clause, her antecedent (the word the pronoun stands for), as a direct object, it needs to be in the objective case for the personal pronoun "who" which, if you recall in the first sentence is "whom" so....
"...her mother punished whom for stealing the money."
Which, that, who Remember the relative pronoun who refers to people only; which refers to things only; that refers to either people or things.—John E. Warriner. Warriner’s English Grammar and Composition. Third Course. Liberty Edition. Orlando, Florida: Harcourt, Brace, and Jovanovich. 1986. 270. But, as you see, who strictly refers to people. It's your choice.
Alternative:
CORRECT: I know the girl that you are talking to.
CORRECT: It was the girl that her mother punished for stealing money.
Best Answer
Option 2, "Thank you, Lord, for the teachers who care for me", is correct.
In order for Option 1 to be correct, there would have to be additional punctuation to break up the sentence appropriately.