Think of how B perceives it:
B: ... think think think think think think think—Sorry, what did you say?
A: [blah blah]
B looks back and thinks of A's utterance as an event which is completely done, finished. Linguists call this view of an event the perfective aspect. Perfective aspect in the past is expressed using the past form of a verb, You said or You did say.
That event, A’s utterance, occurred at a time when B was in a state of thought which started before A's utterance and ended sometime after it. Linguists call this view of a state imperfective aspect. Imperfective aspect is expressed using a progressive construction; in this case, since the state lies in the past, B uses the past progressive construction I was thinking.
Perfect constructions like I have thought and I have been thinking express a state which arises from a previous event and is current at the point in time which you are talking about. Linguists call that time you are talking about reference time (RT). A present perfect construction has the present as its RT: it expresses a state which is current now, at the time of speaking. Since B is talking about a past event, his† RT is the past; in that context a present perfect cannot be used.
A past perfect construction expresses a state with a past RT, a state which was current in the past, so you might think that I had thought or I had been thinking would be appropriate here. But the perfect construction does not express a state denoted by the lexical verb (think) in the construction, it expresses a state which arises from the state or event denoted by the lexical verb. B is not talking about the result of his thinking, he is talking about the thinking itself—so a past perfect construction doesn’t work either.
There is more about aspect here, and entirely too much about perfect constructions here. Be careful not to confuse perfective aspect with perfect constructions—they are entirely different things.
† I make the appallingly sexist assumption that A is B’s wife, only because that’s how this conversation always plays out in my own household.
It should be 'was married' - I'm not sure of the custom in India, but in my experience, marriage (like most earthly institutions) ends when either party passes away. Indeed, Christian wedding vows make explicit reference to this with the line "Til death do us part".
I suppose his wife could still consider herself married to him, but that would be a personal thing. Once one party to a marriage is dead, so is the marriage.
Best Answer
/I think he is out of town/. [present tense] might be used in making a statement to another person in the present.
/I thought he was out of town/. [simple past tense] might be used to make a statement to someone about what you thought before the matter was discussed in your present conversation with another person.