The way the Pali Canon was transmitted was by oral tradition. The composition is in a poetic form, using mnemonic formulae for memorization and recitation. The recitation would have also served a ritualistic or ceremonial purpose. Even the tradition says that in the First Buddhist Council, Ananda and Upali recited the suttas and the vinaya.
Please see "Pali Oral Literature" by L.S. Cousins. I quote below:
Early Buddhist literature is an oral literature. Such a literature is
not without its own characteristic features. A widespread use of
mnemonic formulae is one of the most typical of these. I would refer
to the considerable body of research on the nature of oral epic
poetry. In such poetry the formulae are used both as an aid to actual
performance and to maintain the continuity and form of the epic
tradition.
Both these features are certainly present in the sutta literature. In
the first place many suttas are clearly designed for chanting. We
should assume that, then as now, their chanting would produce a great
deal of religious emotion - the pamojja and piti-somanassa of the
texts. The difference of course would be that the language of the
suttas would still be directly comprehensible to the hearers. In these
circumstances suttas would be chanted by individual monks both for
edification and for enjoyment. We may compare the recitations
attributed to Ananda and Upali in accounts of the First Council. In
practice they would have to be tailored to the needs of the particular
situation ~ shortened or lengthened as required. An experienced
chanter would be able to string together many different traditional
episodes and teachings so as to form a coherent, profound and moving
composition.
I believe that the monks edited and reorganized the Pali suttas over centuries to make them have mnemonic formulae and they also modified similar stanzas to become exactly identical - which is why you can find some standard formulae repeated in multiple suttas. This made it easier to memorize, recite and transmit. This is explained below.
From section 3.2 of the book "The Authenticity of the Early Buddhist Texts" by Bhikkhu Sujato & Bhikkhu Brahmali:
For several hundred years, from the time that separate transmission
lineages emerged in the Asokan period until the texts were written
down, the EBTs were passed down orally in separate textual lineages.
Comparative studies have shown that this oral transmission was highly
reliable and that the core doctrinal material was essentially
unchanged. How did this work,given what we know about the
unreliability of memory? Indian culture provided the template for
highly reliable oral preservation. It is known that the Ṛg Veda and
other Vedic texts were transmitted orally—that is,by memory—with
extreme accuracy for over two thousand years.
In his comprehensive study of the Majjhima Nikāya, Anālayo considers
the impact of oral transmission and concludes: “At the same time,
ratherthan giving us a completely new picture of early Buddhism, what
my comparative study of the parallels to the Majjhima Nikāya
discourses yields is a reconfirmation of the essentials, with
occasional divergence in details.”
In the field of oral literature, there is a distinction between texts
that are to be memorised verbatim, as in the Buddhist and Vedic
traditions, and those which serve as springboards for storytelling, as
in oral folk traditions.
The latter are subject to natural evolution and variation; they are
meant to adapt to the teller and the situation. Such, according to
Oldenberg, are also found in Buddhist literature, specifically in the
Jātaka collection of the Khuddaka Nikāya. But the former, which are
codified and fixed texts, are meant to be preserved in exact form, as
in the case of the EBTs.
The Indian oral culture developed various methods to ensure that this
was achieved. Such methods pervade every aspect of the EBTs, and
include:
- Repetitions of words, phrases, passages and whole Suttas;
- Standardisation of words, phrases and passages;
- The use of synonyms;
- The use of the waxing syllable principle;
- Sound similarities;
- Concatenation of Suttas or other textual units;
- Formal structures, especially ABA;
- “Summary” and “exposition”, which is a standard feature of Indian oral education;
- Framing narratives to define the limits and give the context for the spoken material;
- Verse summaries of prose teachings (especially in the Aṅguttara);
- Similes (usually in an ABA structure);
- Numbered lists;
- Group recitals.
From this page, we find the story about Ananda's eidetic memory, but I could not find the original source for it.
Shakyamuni Buddha had a famous disciple, Venerable Ananda, who bore
the nickname of “The Learnt Man”. As Venerable Ananda has a rare
ability, an eidetic memory, he could remember every word of Buddha’s
teachings. Because of his special talent, many often asked Buddha what
good deeds Venerable Ananda had done in his past life to deserve such
a blessing.
Buddha replied, “Ananda’s eidetic memory was a result of the
accumulation of good deeds in his past life.”
He explained, “Several lives ago, a master monk demanded his novice
monk to memorise all the sutras he was taught and would be reprimanded
or punished if he did not meet the master monk’s expectation. On a
fateful day, the novice monk received no food offering all morning and
became worried, as spending more time on the streets would mean less
time to study his sutras. In desperation, he started weeping. An elder
approached this novice monk to show his concern, and after learning of
his difficulty, he told the novice monk to go to his house for food in
his subsequent days. Having secured a source of food offering, the
novice monk could spend most of his time learning his sutras.”
Putting the story into perspective, Buddha said, “The master monk was
Buddha Dipamkara, the novice monk was me, and the benevolent elder is
the Ananda today. Ananda’s good karmic deeds had gained him his
eidetic memory in his present life, which allows him to remember every
word of dharma preaching.”
Also, from "The Life of Ananda, Guardian of the Dhamma" by Hellmuth Hecker and Ven. Nyanaponika Thera:
In selecting Ananda as the treasurer or guardian of his Dispensation,
the Buddha had chosen one whose personal qualities coincided perfectly
with the demands of the post. By virtue of his devotion to learning,
Ananda was ideally suited to receive the manifold teachings delivered
over a forty-five-year period; by virtue of his phenomenal memory, he
could retain them in mind exactly as spoken by the Master; by virtue
of his sense of order, he could be relied on to preserve them in the
correct sequence and to explain them in such a way that the structure
of ideas accorded with the Buddha’s intention; and by virtue of his
steadfastness, he would so endeavor that the pupils under his charge
would receive the teachings fully and be properly trained so that they
in turn could pass them on to their own pupils.
More comments on Ven. Ananda from the suttas:
The foremost of my monk disciples who are very learned is Ānanda.
The foremost of my monk disciples with a good memory is Ānanda.
The foremost of my monk disciples with an extensive range is Ānanda.
The foremost of my monk disciples in retention is Ānanda.
The foremost of my monk disciples as a personal attendant is Ānanda.
AN 1.219-234