Let's say I have a friend who is married and before the last marriage he was already married a few times. If I ask them "When did you get married?" can they answer with "What time?" if they want to know what marriage I am asking about, the first, second or third?
3 Answers
You're very close. "What time?" is likely to be misunderstood since it sounds like "what time is it?" (i.e., it sounds like the question is about the time of day rather than which instance is being referred to). This ambiguity arises because English uses the same word "time" to refer to time of day and to occasions or instances. "Which time" is usually understood to mean "which occasion/instance" while "what time" is usually understood to mean "what time of day."
So, the more natural response is "which time?"
Saying "What time?" sounds like "When?" so, as a point of time on the calendar.
So, they should say: "Which time?" which refers to "Which occasion?"
It would be more common, at least in American English, to say "which time."
When what is being asked requires specification of one or more from among a well defined set, which" is generally used in the U.S. "What" tends to be used when the set is less clearly defined.
Which book do you recommend
tends to imply an agreement on some definite set of books, say those on a particular topic in a particular store.
What book do you recommend
is more open ended.
The dividing line is certainly indistinct; there probably are regional and even personal differences in usage. But in your example of different marriages between the same couple, the set is so well defined that I doubt anyone in the U.S. would prefer "what" over "which."
EDIT: While I was writing, other answers were provided, and they focused on specifics relating to the meaning of "time" whereas my answer focused on the more general question of "what" versus "which." I do not disagree with those other answers.