"If the key is lost, (then) a locksmith can cut another for you."
As you see, this is a usual \'if…then\' sentence.
As a question, it becomes:
"If the key is lost, (then) what should I do?"
Inverted, the sentence becomes:
"What should I do if the key is lost?\"
Here, you notice the expected verb-subject inversion: 'should I'
Then, shortening the sentence:
"What... if the key is lost?"
Now, it seems as if this question is not following the rules! ; but this is because we have omitted part of the sentence. The whole point of asking the question is to find out what I should do! It is not necessary to include the words, since the meaning remains clear. In the full sentence, the rule WAS obeyed, with the subject and verb inverted.