"Houston, we have a problem." Interesting, isn't it? Where do we go from here, then? Good question, which is why we have a billion theories—two or three for each scholar who's worked on it for the last 500 years of so : )
Seriously, we know it has to be trained and educated scribes. Typically, those exist in the temple or royal court; those are the only institutions that can afford to support the infrastructure necessary to provide the education necessary to learn to read and write. But the prophetic books are highly critical of these very structures...a conundrum!
The traditional answer has been that the prophetic books were recognized as inspired by YHWH and therefore preserved—even though they were highly critical of the very institutions preserving them. But, that begs the question, doesn't it?
So in the end, we don't really know...that's not very satisfying intellectually, is it? Maybe faith is the missing factor, then.