FWIW, I've read that a lot of guys who find a specific type of factory ammo that shoots well for them, try to buy a whole bunch from the same lot number (often stamped inside one of the end flaps on the cardboard box), because different production runs of the same ammo from the same factory can sometimes shoot differently. Even within the same lot, there will be differences (hopefully small) that result from imperfections or batch differences in the components and variations in propellant metering, etc.
If you reload, you might be surprised at how much difference there can be in the "same" component from the same manufacturer, which is something I picked up on when I started to weigh my bullets and cases. I've seen commercial cast handgun bullets vary in weight +/- 5 gr out of the same box, and cartridge cases that were 20% heavier than others with the same headstamp. I recently finished one jug of Unique and started on another (different batch), and the same volume went from 5.0 gr to 5.5 gr in weight (10% difference). You can watch for that kind of thing when you're reloading, but if you're buying factory ammo you're dependent on whatever quality control process the manufacturer uses.
Obviously, the ammo isn't always the problem. Sometimes, even small changes like temporarily removing the stock can cause the same rifle to shoot the same ammo differently (happened to a friend with a Ruger No. 1 in 270 Winchester ). Some folks might blame the ammo for that kind of thing, when in reality it's caused by different torque on the action screws, or pressure on the barrel, or whatever. We've probably all heard stories about firearms that had fouling in the barrels, or scope ring / mount screws that started to loosen up, etc.
And obvious changes can definitely make a difference - when I swapped stocks on a .22 target rifle years ago (from laminated wood to carbon fiber), I didn't expect any big changes. But group sizes with the its preferred ammo (Green Tag) opened way up, and I had to find something different (Winchester T22) to get the groups back where I wanted them.
As always FWIW, IMHO, YMMV, etc., etc.
