You seem to be assuming that the only bad thing about pain is that it will be remembered. But is this right? I think not. One way to argue against the assumption is by analogy: if the assumption were correct, then presumably the only bad thing about memories of pain would be that they will be remembered. And so on up. So long as all sentient beings die eventually, there would then be nothing bad (or good?) about their experiences because all memory of them would eventually disappear.
Rejecting what you assume, we would say that pain itself is also distressing and therefore bad. In fact, without that distress of pain itself it's hard to understand why memories of pain should be distressing.
If pain itself is distressing and bad, then it makes sense to avoid and alleviate pain. And this is in fact what we routinely do when we offer palliative care to a patient who would otherwise die in great pain. The case of the animals you describe is essentially similar. Just as it is less bad if the last few hours of a dying patient are pain-free rather than full of pain, so it is also less bad if an animal soon killed in some experiment is pain-free rather than in agony during its last hours.