I'll try to explain it as I see it.
As a pokémon is "caught" I believe that it's genetic data and individual composition is recorded digitally and sort of "locks" the pokémons' matter into the ball. Then it'll be able to restore that matter when releasing the said pokémon, and when the pokémon returns to it's ball its new composition is recorded to restore upon the next release.
A lower level Pokéball (a budget version) is worse and will do it slower, making the struggling pokémon's matter move around in the ball and break the weaker forces of the ball. (If the device "knows" [records] the composition of the pokémon it will be able to "know" what to hold.)
A higher level Pokéball will do it with less time and effort simply as it's more technologically advanced. The Master Ball does it instantly.
Some specific types (like Net ball, Level ball, Heavy ball) will work better on specific types of pokémon because they're already pre-set to specific characteristics of pokémon that they're supposed to catch, thus reducing the time it takes to record by taking a sort of "data shortcut" as they're "pre-filled" with some data. The Dusk ball probably is set to certain characteristics of pokémon living in the dark and in caves, for example.
In the games the balls will break if it'll fail to catch the targeted pokémon. I'd say it's because it will experience a fatal energy overload from the too strong and vital struggling of the pokémon and make the energies unstable. That's why you need to weaken the target pokémon first. In the anime, however, the balls are more protective against the struggling forces and won't break if they fail to capture a pokémon.
Also anime-wise, some pokémon can go out of their ball at will. I'd say they struggle enough so that the ball gives in and will release them, and as they're in full energy and can struggle out of the "seal" of the device.
And about if a pokémon doesn't have to enter a Pokéball if doesn't want to:
It's simply the choice of the trainer to not make it's pokémon uncomfortable doing what it doesn't want to do. And if it's still forced to enter it it can struggle out at will. Then why do more powerful pokémon decide to stay within the Pokéballs, like legendaries? Because they've gained respect for the trainer after being defeated and caught. They know that their immense strength has been curbed and that they've been bested by someone who is above them in skill and "strength".