The latter, surprisingly enough. While poké balls are indeed capture devices (meaning there is a baseline capture rate for all of them), whether or not they can contain their captured pokémon until a trainer releases them depends entirely on the willpower of the pokémon in question. You see, inside every poké ball is a capture grid that works like an electrical net. So long as the pokémon’s will is neutral, it won’t disrupt the grid, and the ball will remain closed. If, however, the pokémon passionately wants to get out, there’s a chance they’ll disrupt the grid, which causes the poké ball to think a trainer has opened it, thus leading the ball to eject its contained pokémon. For some reason, smaller or basic-level pokémon seem to be more adept at disrupting the grid than larger, more evolved ones, which is why you might see pikachu break out of their balls more often than charizard, even if they’re both equally bonded to their trainers. Some smaller pokémon will even disrupt the capture grid every time, which means their poké balls are really only effective for the initial capture. (This occurs especially with pikachu.)
You may think this is a design flaw, but actually, it’s perfectly intentional. While, yes, a poké ball’s main points are to ensure a pokémon can be withdrawn from a dangerous situation or to prevent rampages, the poké ball is also designed to allow a pokémon to break free in dire situations, such as those in which its trainer is in danger and unable to summon them. That and it’s just seen as more humane to allow a pokémon to break free if it has the overwhelming need to shower its trainer with affection.