Amazon's system is such that a packer shouldn't run out of any boxes but it does happen. However, the packing lines are segregated such that one line deals with multiple small items with a certain range of packaging, another line will deal with single larger items again with an appropriate range of packaging, the system is really quite slick.
The whole bangshoot is driven by a huge database of items, just about every possible property of an item is held in the database including its physical size and weight. Those details (along with value) are responsible for allocating the type of packaging. Problems however arise if a mistake has been made in inputting the item size to the database, e.g. a USB stick that is .05m x .005m x .025m is input with the first dimension as 0.5m……..your going to get too big a box.
It doesn't happen often, the hundreds of thousands of packages that get the the right packaging and get delivered correctly don't make news but if you have an agenda, waste, recycling, don't like Amazon etc. then the very small percentage that are overpacked or go astray make a much better story.