I wonder which of the following questions is grammatically correct:
What country is this flag?
What country is this flag of?
Of what country is this flag?
How would you ask this?
None are grammatical although the second and third are close to grammatical.
What country is this the flag of?
Of what country is this the flag?
are grammatical. Neither, however, would be idiomatic in speech or informal writing.
Which country's flag is this?
is probably typical US speech
Alongside Jeff's suggestions in their answer, although I don't think 'Which country's flag is this?' is typical US speech, you might consider using the following sentence:
Which country does this flag belong to?
It isn't from any of your options provided, but is widely used.