I would say that the most directly relevant word for being interrupted while in the middle of something else is being 'sidetracked'. Hopefully you will remember what your original task was once you are done with the task that interrupted or diverted you, but sometimes that's not always the case.
There are several psychological factors that could cause someone to get sidetracked---such as not actually wanting to complete the original task. In which case, "allowing" yourself to be sidetracked could be a coping mechanism or avoidance behaviour.
(But I'm no psychologist, so I can't go into that in any more detail. Except to say that, depending on the situation, such things are not necessarily unhealthy. Also, there could well be a more scientific term for 'sidetracked' that explains the phenomenon at a neurological level.)
You could also be tired, or in another physical state that hinders concentration.
If it's something that you're prone to experiencing but want to avoid, it can sometimes help to keep repeating the task you set out to do in your head. If it's constantly "playing" in your conscious, it's more difficult for you to forget about it. (Of course, the thing that sidetracks you may seem more important at the time.) You could also write down the original task on a piece of paper and carry it with you . . .