The given sentence is in past tense, as the clause "when you wrote" suggests.
Option B: 'Did you have' is in simple past tense and asks if the person 'had time'.
(When we use the verb 'did', it already refers to the past tense. Hence it is followed by a present tense verb 'have' and not a past tense verb.)
So, option B is correct.
Option A: 'Do you have' refers to the simple present tense - a habit or general truth. It does not refer to the past.
Option C: 'Have you had' is in the present perfect tense and states an action that just happened in the present. But the action has already happened in the past.
Option D: 'Had you had' is in past perfect tense. It states an action that completed in the past, before another action happened.
But here the actions don't happen one after the other. The first action 'when you wrote' states a past time and the second sentence asks about that past time.
Hence options A, C and D are wrong.