they have portals inside of them, that portal connects to another portal in a room filled with never ending bullets, that's where their bullets come from
It isn't shown in the game, but according to the commentary, there's another machine right below that one that immediately takes the turrets out of the boxes and distributes them to the test chambers.
You "encountered" this while REplaying Portal 2? There's like a bunch of those right infront of you on several spots, you have to be the blindest faggot with the weakest attention skill not to have seen any of them on your first run.