I am aware of this question (I anticipate people linking it to this one in less than 3 seconds since I hit "Post"), and I am asking something more precise and somehow different.
When some enemy force boards the ship, why doesn't a program run in the computer that just performs the following task: while there is energy available and the transporter is up and running, every member of the enemy force is transported to a precise location. No need to be violent: let's transport them to a dedicated brig, their weapons disintegrated. I imagine the Cardassians or the Dominion tweaking the program to beam the enemies 10 meters outside the hull.