Option C is the correct answer because according to the given words, the statement to be made is in the past tense, hence, was having dinner is correct, and ‘came’ is the past tense of ‘come’ hence it is correct.
Option B and D are incorrect because come is in the present tense in those, while the question is in past tense
Option A is incorrect because I had dinner when you had come, is incorrect, it should be when you came.