grammatica dividit
The first scribes were the archivists and scriveners in the employ of the official bureaucracy of the fertile crescent in the late fourth millennium before Christ. The professional development paralleled the need for records of economic transactions, in origin nothing more complicated than a clay tablet stating something like 'I sold 4 sheep to Utuhegal the Leatherworker today', then sealed and placed on the shelf until Utuhegal tries to sue for non-delivery of 4 sheep.
But let's concentrate on purely mechanical aspects here. The need for scribes grew with the need for records of political and social transactions; the more complex these became, the more recordings were needed. Thus we have many records and many scribes being educated in the Akkadian empire of Sargon, in the Ur III period, and in the Babylonian state of Hammurabi, but relatively few during the unstable periods, and so forth.
Scribal training was systematized relatively early, but the best records still date to the Old Babylonian period. Most likely, scribal training remained within families, though this is far from certain, and began at a relatively young age. We can trace the development of these school-boys (female scribes were rare) through school texts, identified archaeologically by their distinctive shape, content, and failures in writing (though it is admittedly almost impossible to distinguish between the writing of an advanced student and an incompetent, practicing scribe). In the first stage, a student simply learned how to form basic strokes, then signs; some 300 were required to write a workable cuneiform text. In the second stage, he began copying dictations, learning the terminology necessary to write legal documents and form letters. Here also he began with lexical lists, tablets divided into three columns containing a Sumerian cuneiform sign, its pronunciation, and its Akkadian meaning. Thousands of these remain, and seem to form the basic method of learning Sumerian as a foreign language, organized sometimes alphabetically (first sign bu, second ba, third bi, etc.), sometimes topically (types of trees, types of birds, etc.). The last stage of training was instruction in literature, in which the students composed and copied temple hymns, wisdom literature, and traditional stories and mythology. These basics of literacy were supplemented by mathematics, astronomy, and even music.
The scribal schools (Sumerian edubba) were run by professional teachers (called "fathers"), who with their own teaching assistants ("elder brothers") taught the "sons of the tablet house" in their particular fields; we know most schools had a professor of Sumerian to teach that language separately (whether lectures were held in Sumerian or not is still a matter of debate). Corporal punishment was quite common for slackers, and many so-called "school days texts" talk about poor conditions, ill treatment by disinterested teachers, and seditious students unwilling to learn their lessons. Advancement required successful completion of exams: translating obscure Sumerian lexical terms, or listing technical terms used by metal-workers. The individual schools were often, but not always, connected with the temples or palace. Indeed, the scribes were an almost completely lay group; priests and royal officials were usually illiterate.
The social importance of these scribes is not in the creation of a new and thriving body of literature, though certainly remarkable innovation takes place through the 3000 years of Mesopotamian political history, but the preservation of a traditional and conservative element. Early military and economic expeditions took along scribes, and ensured the expansion of the cuneiform writing system throughout the Middle East, adapted by the Elamites, the Hittites, the Persians, and countless other, lesser peoples. With the writing system came a rich literary tradition, religion and mythology, and ritual and cultural practices which spread to the foreign peoples and reinforced the dominance of the Mesopotamian city-states and empires. The fixed written tradition, in function similar to the oral traditions of the Irish bards or the Indic Vedas, served as a carrier of cultural continuity which survived countless political upheavals. This scribal tradition allowed Babylon, the site of one of the most important scribal schools, and Marduk to survive long after the imperial torch had passed to Assur, and the Babylonian Berossos in the 3rd century B.C. to continue writing about 2000-year old stories for a Greek audience.
Though of course this whole business above has been limited to Akkadian Mesopotamia, the same principle applies to Rome in the 4th century of the empire, Byzantium in the dark ages, Egypt in the interdynastic periods and first millennium time of foreign dominance, and the monasteries of Medieval Europe. Scribal schools and education, though functionally supporting the administration, became guardians of language, preserving the mechanics of literary, cultural transmission.