1. I remember writing a letter.

2. I remember that I wrote a letter.

3. I remember to write a letter.
4. I remember that I have to write a letter.

Does #2 mean #1?
Does #3 mean #4?

In #4, can we use 'must' or 'should' instead of 'have to'?

#s 1 and 2 mean the same thing, yes.

#3 would be better if you make the verb future: "I will remember to write a letter."

#4 is fine, and you can also substitute "must" or "should."

1. "I remember writing a letter." - This sentence indicates that you have a memory of the action of writing a letter in the past. It implies that the act of writing the letter has already taken place, and you have a recollection of it.

2. "I remember that I wrote a letter." - This sentence also suggests that you have a memory of writing a letter. The difference from the first sentence is that it explicitly states the past action was completed. It emphasizes the fact that you have knowledge of having done it in the past.

Regarding your questions:

Does #2 mean #1?
Yes, #2 does mean the same as #1. Both sentences convey the idea that you have a memory of writing a letter in the past. #2 simply clarifies that the action of writing the letter has been completed.

Does #3 mean #4?
No, #3 does not mean the same as #4. There is a difference in meaning between the two sentences.

In #4, can we use 'must' or 'should' instead of 'have to'?
Yes, in #4, you can indeed use "must" or "should" instead of "have to" to express a similar meaning. For example, you can say, "I remember that I must write a letter" or "I remember that I should write a letter." All three expressions imply a sense of obligation or necessity to write the letter.