The mishna and gemara indicate that the melacha of tzeida is not violated by maintaining a situation of being trapped, and is only violated by doing an act that actually traps an animal or bird that was previously not trapped. Therefore, if an animal has already been trapped or tied down in a house, one would be allowed to close the door, and even if they later untie the animal, they would not have to open the door (Ran explains that this is the intent of the mishna למה זה דומה לנועל ביתו לשמרו ונמצא צבי שמור בתוכו).
The Ran quotes a Rashba who understands from a Yerushalmi that if a deer ran into a persons home, one would be allowed to close the door of his home with the intent of protecting his home, even if he also intends to capture the deer that is inside. Although it would be forbidden to close the door if the sole intent would be to catch the deer, they can close the door for the purpose of protecting their home, even if their intent is also to capture the deer. The Ran is amazed how the Rashba can permit this. This seems to be a classic situation of a פסיק רישא which is forbidden even is his intent was not at all to capture the deer since it is inevitable that the deer will be trapped. How can the Rashba permit closing the door with the intent to trap the deer in addition to protecting the house? Therefore, the Ran explains that the Yerushalmi is simply saying that if one closed the door to their house with the intent of protecting their home, and later realized that the deer was inside, they can maintain the status quo and don't need to open the door to release the deer.
The M.B. 316:25 paskens like the Ran and writes that it is forbidden for one to close the door to their home with the intent of protecting their home if they know that there is a deer that will be trapped inside, even if they are not intending to trap the deer. The M.B. explains that closing the door when one knows that the deer is inside would be an issur d'oraysa (it is a pesik reisha that they want, even thought they aren't intending for it). Certainly if their intent would be to capture the deer it would be forbidden m'doraysa.
The Sha'ar Hatziyun (32) suggests that perhaps even the Rashba would only permit closing the door if the primary intent would be to protect the house, not when he is equally intending to trap the deer and protect the house because that would contradict a gemara in Pesachim which implies a double intent (one being mutar and the other asur) is forbidden.
The Poskim do not follow the controversial and difficult position of the Rashba. R. Akiva Eiger cites the Shulchan Aruch (3) who forbids closing a box for the purpose of protecting its contents, if one knows that there is an insect inside that will inevitably be trapped. This is an identical case to the deer in the house about which the Rashba and Ran argue, and indicates that the halacha is like the Ran against the Rashba. The Pri Megadim (Eishel Avrohom 11) isn't convinced by the proof from Shulchan Aruch because in that case his primary purpose in closing the box is because of the bug, unlike the case of the Rashba where the need to close the door to protect the house is at least as important to him as trapping the deer.
In short, the opinion of the Rashba is very difficult to comprehend because it contradicts the standard rule that even by a דבר שאינו מתכוין a p'sik reisha is forbidden, and the Rashba even permits a דבר המתכוין such as intending to trap in addition to protecting one's home.
The Shiltei Giborim tries to justify the opinion of the Rashba and writes:
והשתא לדברי הרשב"א נמצינו למדין דאע"ג דקיי"ל דפסיק רישיה אסור, היינו דוקא שבאותו מעשה דעביד הפסיק רישיה אינו מתכוין ואינו עושה דבר היתר עמו, אבל אם באותו הפסיק רישיה שעושה, עושה ג"כ דבר היתר עמו ויתכוין גם לדבר היתר אז אפילו עביד פסיק רישיה ומכוין גם לו שרי
The Shiltei Giborim seems to understand that in the classic pesik reisha such as dragging a bench, the inevitable reaction of the dragging which the making of the hole, has no element of heter to it. Therefore, even if he isn't intending to make a hole, it is an inevitable result that is forbidden. But when the result of the action has both a heter and issur component, it is permitted. The difficulty with this approach is that we should simply view the action to be protecting the home, and the result to be an inevitable trapping of the deer which is a classic pesik reisha. וצריך עיון בדברי השלטי גבורים.