1. Where do you buy a scarf?

-I buy it at the department store.

2. Where do you buy the scarf?
-I buy it at the department store.

3. Where do you buy scarves?
-I buy them at the department store.

(Which question is correct grammatically?)

All are grammatically correct, but only #3 is the smooth and commonly used expression. To make #s 1 and 2 better, here's how I'd rephrase them:

Where do you go when you want to buy a scarf?

Where do you go when you want to buy the perfect scarf for your mom?

All three questions are grammatically correct.

In question 1, the word "scarf" is singular, so the correct form is "Where do you buy a scarf?"

In question 2, the word "scarf" is again singular, so the correct form is "Where do you buy the scarf?" The use of the definite article "the" implies that there is a specific scarf the person buys.

In question 3, the word "scarves" is plural, so the correct form is "Where do you buy scarves?" The use of the plural form indicates that the person buys multiple scarves.

So, depending on whether you are asking about a specific scarf or scarves in general, any of the three questions can be grammatically correct.