Is time from acceptance to publication purely a matter of space issues?
I'd say your second option, various factors impact the progression of an accepted paper.

Commissioning editors might decide that they commission an edited issue with academics deciding on the selection and groupings of articles, and that will disrupt the 'queue' of all accepted articles you mention.

Otherwise, commissioning editors might notice that some recently-accepted articles fit nicely around a specific theme or share a common characteristic that make publishing them together valuable, regardless of the order they were accepted.

Essentially, publishing is a human process, with the advantages and drawbacks that entails. If publication was only down to space, things might be very different.