The correct option is
D By whom was Grammar taught to you?
The given sentence is in the active voice, as the subject 'Who' performs
an action 'gave' against the object 'you' in the interrogative.
If this sentence is changed to passive voice, then the subject is also changed, in order to retain the meaning of the sentence.
So,
the object takes the place of the subject and vice versa and the word
'by' is introduced as now the subject receives the action by the object.
The verb form of the sentence is also changed from active form to
passive.
'Subject (Who) + verb (taught) + indirect object (you) + direct object (Grammar)' changes to:
'By
+ subject (whom) + auxiliary verb (were) + indirect object (you) + main
verb (taught) + direct object (Grammar)'
The
passive form of 'taught' in the simple past tense is 'was/were taught'.
This can be seen in option D, hence it's the right answer.
Option A: The verb 'were' comes before the object 'you' and not after, because it's an interrogative sentence.
Option B: 'Were' will come before the object 'you' and won't be followed by the main verb 'taught', since the phrase 'taught you' is active.
Option C: The error lies between these words 'Grammar you taught' since the sentence ends with the verb 'taught'. Sentences do not end with verbs, and are placed as close to the subject as possible.
Hence options A, B and C are incorrect.