I was wondering why in the following sentence "was" has to go at the end?
She asked the boy what his name was.
I was wondering why in the following sentence "was" has to go at the end?
She asked the boy what his name was.
You need "was" because it's the verb in the dependent clause.
The phrase "what his name was" is a subordinate/dependent clause. It is introduced by the relative pronoun "what" and, because all clauses have both a subject and a verb, must include a verb to complete the thought.
You can think of the semantics of the dependent clause as equivalent to: his name (subject) was (verb) "what" (predicate nominative).
As for the positioning of the verb: you could write "She asked the boy what was his name," but it is extremely forced and uncommon formation in most situations. The form that you used in your example ("...what his name was") is b far more common and accepted.
This word order is not actually as odd as it may seem. It's not that we are post-pending the verb at the end of the sentence; we are simply following standard S-V word order. The difference is that the object that completes the predicate happens to be the relative pronoun; thus, it's not that the verb is moved to the end of the sentence, but that the object following the verb is moved to the beginning of the dependent clause.
Compare:
- This is the toy that I always wanted.
- I always wanted that.
The verb doesn't always come last:
- He is the man whom I saw in the alley.
- I saw (whom / the man) in the alley.
She asked the boy what his name was.
She asked the boy, "what is your name?
"What his name was" is an indirect question". "What is your name?" is a direct question.
The first sentence is in reported speech (indirect speech), whereas the the second sentence is in direct speech. The verb "is" in direct speech has been changed to "was"in reported speech as the reporting verb (in the direct speech) is in the past.
According to grammar, you turn the question form to the statement form in reported speech, that is, instead of the verb + subject form(was his name), you use the subject + verb form (his name was).