The correct option is
D
had been waiting
The given sentence states two actions, both are in the past. The word 'before' means that the first past action took place before the second past action "you came".
Also, it states a duration of time "for only a few minutes". Hence the most suitable option should be in continuous tense, as it has taken place over a period of time.
Option D: 'Had been waiting' is in past perfect continuous tense and agrees to the given sentence as explained above. Hence option D is correct.
Option A: 'Will wait' is in the future tense. But, the action happened in the past, before another past action 'you came'.
Option B: 'Have to wait' expresses an obligation to wait. It states an action without stating the tense. This isn't consistent with the second past action.
Option C: 'Have been waiting' is in the present perfect continuous tense. But, the action here happened in the past.
The difference between past and present perfect continuous is that in the former, the action took place in the past and ended in the past, whereas the latter action has just been completed in the present.
Since another action (before you came) already tells us that the action completed way before the present, this is not the required tense form here.
Hence options A, B and C are wrong.