Domestic cats don’t understand the reason for doors and dislike them. They are a human invention and in the cat world they would not and should not exist. Domestic cats also do not distinguish between indoors and outdoors. Domestic cats obviously recognise the difference in the landscape between indoors and outdoors but the concept of being indoors or outdoors is also a human construction.
Therefore, doors simply present a barrier to a domestic cat when he or she is patrolling his home range (his territory). Cats like to constantly patrol their home range (their home). They return to their base after patrolling. Cats like to do a brief survey of their territory. They return with information about the activities of other cats. They do this through scent marking. The scent of a cat fades over time and therefore domestic cats can assess when and where other cats have been on their territory.
As the cat likes to make a tour of duty of his territory frequently he will want to come in as soon as he has gone out but I stress, cats do not “go out and come in”; they are simply walking around their territory and the door presents a barrier.
Another reason why cats frequently like to patrol their territories is to deposit fresh scent at significant points within the boundaries of the territory to tell other cats that it is theirs and that they are present.
I don’t think that there is any other clever reason why cats want to come indoors the minute you let them out. This behaviour is simply a product of a domestic cat living in a human world full of human-made objects which are unnatural (not created by nature). Let’s remember that the domestic cat is not far, in respect of attitudes and personality, to their wild cat ancestor.