a very TL;DR summary is that they can throw you out, and you can sue them for it later if it was for invalid reason, but you still get thrown out. Similar rules happen on the sea, which results in hilarious summaries like "yes, a Disney Princess can sentence you to death and do the execution, if specific conditions are met" (condition being "evacuated on escape boat/device of a Disney cruise ship"). The summary is hilarious, but the same applies to plane's captain so long as flight operations are ongoing, including pre-flight preparation after embarking.
A better analogy: If I purchase a movie ticket, the theater cannot just kick me out at will, right? Oh wait - yes they can.
This isn't hard.
https://www.govinfo.gov/content/pkg/USCODE-2011-title49/html...
When looking for the reasons behind the growing prevalence of security concerns in modern society (both from governments and companies), one can hardly avoid the conclusion that it's just the perfect justification for anything.
The way the passenger was removed was wrong, and potentially illegal (I assume you can’t shoot someone because they are trespassing on your property, presumably you can’t injure them either). I believe United paid some hush money to stop him suing, but I see nothing to show the captain wasn’t allowed to have him removed.