- Why do you ask?
- Why did you ask?
- Why have you asked?
- Why are you asking?
Any of these responses are possible.
The continuous aspect of "Why are you asking?" establishes the act of asking as an ongoing process -- a process with a duration. In the present tense, this implies that the process began in the past and will end (if it ends at all) in the future.
That can work. In this context, the asking began in the immediate past of a few scant seconds ago and continues through the immediate future of an instant or two from now.
For me (and apparently for P2) the present continuous isn't the most natural choice. From my perspective, the act of asking is not an ongoing process. The action had a brief duration that began when the question was posed and ended when the question was answered. This duration has no relevance to the follow-up question. I regard the act of asking as telic, as a self-contained action the internal components of which don't matter to me.
The perfect aspect of "Why have you asked?" makes sense from a telic perspective. The thing that exists in the present tense is not the action of asking but the result of asking.
That can work. In this context, we can regard the asking as a fact rather than an action or a duration.
Again, I don't find this option to be the most natural choice. My native dialect is American, and many American dialects prefer to avoid perfect constructions when they are unnecessary. In many cases, a past-tense action is enough to imply a present-tense situation or fact.
The past tense of "Why did you ask?" simply places the action of asking in the past.
That can work. The act of asking starts with posing the question and ends with accepting an answer. If we assume that P1 accepted the answer given, then the action can simply be placed in the past.
For me, this exchange is too immediate to be comfortably placed in the past. I am more likely to consider the question and answer exchange to be so recent that it is part of the present moment.
This leaves us with the option that P2 chose. "Why do you ask?" is a present simple construction. A more descriptive name for this construction is the present indefinite.
Although it is called "simple", there is nothing simple about interpreting the indefinite aspect. The entire point of the indefinite aspect is that we do not know from the verb form alone what aspect the clause has. It could be habitual, periodic, iterative, gnomic -- the list goes on and on.
The specific aspect is often indicated adverbially:
- Why do you sometimes ask?
- Why do you frequently ask?
- Why do you always ask?
- Why do you ever ask?
- Why do you ask at a time like this?
You've been taught to prefer the present continuous construction in order to avoid unintentionally implying any of these aspects that the indefinite construction allows. The continuous aspect implies an immediacy and a concreteness that the indefinite aspect cannot express on its own.
In your example conversation, this seems to be an intentional and purposeful implication. P2 doesn't care about the duration of the action, or whether the action is complete or ongoing. When it comes to placement in time, P2 considers the action recent enough to be included in the present moment.
You didn't cite a source for this bit of dialogue. I can't check whether my assumption is correct. If it makes sense for P2 to assume that P1 habitually asks this question, then it makes sense for P2 to imply the habitual aspect with an indefinite construction.