Why were the Sutras Composed?

Sutta is the Pali word, Sutra is Sanskrit. Both generally refer to records of lectures, sermons, or discourses delivered by the Buddha Shakyamuni. Sutta refers to the discourses collected in the Pali Canon of the Theravada School.
Neither the Suttas nor the Sutras were directly composed by the Buddha. Rather, they are third person accounts which describe the setting of the lectures and the content of the Buddha’s words. In fact, the Buddha does not even appear in some Suttas; some record or describe conversations of the Buddha’s disciples.
In the cases of the Sutras [of Mahayana], these often start with, “Thus I have heard. At one time the Bhagavan {Blessed One, World Honored One} …”. So the third person narrator does not even claim to have witnessed the events; he or she is simply relaying what they claim to have heard.
This may also be true of the Theravada Suttas. However, it is generally conceded that the Pali Canon contains recollections of the Buddha’s actual words. I don’t know if they are verbatim accounts, it seems like they were set to verses, so as to make memorization easier. I don’t know that the Buddha spoke exactly that way.
The Pali Suttas were not, however, recorded at the same time they were composed; they were handed down orally for several centuries. I have noticed there are often long versions and short, condensed versions of the same sutta. The long versions appear to be more literal accounts. The short suttas seem to introduce mythical elements, as metaphors, to replace ‘technical’ passages that are hard to follow.
On the other hand, it is generally thought that the lectures or sermons recorded in the Mahayana Sutras are not the Buddha’s actual words. Perhaps the Buddha appeared in his Ascended Body {Sambhoga-Kaya] and spoke them; I don’t know. It seems likely they were composed by monks living around the same they were recorded, and attributed to the Buddha posthumously.
That makes the Mahayana Sutras problematic to interpret. We do not know who wrote them, exactly when, or what their intent was. In fact, it appears that not all of them have the same intent. I think that most of the time, the intent is to expand upon themes found in the Agamas [a sankrit version of the nikayas, extant only in Chinese, but known to the early Mahayanists]. The Prajna Paramita Sutras are possible, or even probable, examples of this.
At least one Sutra, the Vimalakirti, looks like a politically motivated satire, written by adherents of one sect, and intended to pan or belittle a rival sect. I am guessing, among other things, those rival monks being panned believed that only male monastics could attain Enlightenment in this life, and that nuns and lay followers were inferior to monks.
In the Vimalakirti Sutra, the names of the Buddha’s disciples appear to be given to fictional characters who seem to represent such arrogant, narrow minded, nihilistic, elitist monks. In the tale, these characters meet up with a Lay follower, who puts them to shame.
I think that, because that satire was later taken by some to be a literal historical account, Shariputra and the other arahant disciples of the Buddha came to be thought of arrogant buffoons. The terms Arhat/Arahant, which originally meant one who attains Enlightenment in this life; and people of the two vehicles [Nijo], came to indicate self centered monks who were incapable of ever reaching Enlightenment. Some East Asians still use Sharihotsu as a pejorative term for intellectuals with swollen egos.
Hinayana, which originally meant a base, vile, or lowly vehicle, came to be pejorative for the narrow minded interpretations of the rival sect targeted by the Vimalakirt Sutra. This was later misconstrued to be a label for the Buddha’s teachings, or Suttas, as recorded in the Agamas. That is why, IMO, the Lotus Sutra steps in and redeems the original Arhats {Sanskrit} or Arahants {Pali}.
Much later, the Nikayas of the Pali Canon and Theravada were even falsely or mistakenly slandered as “Hinayana.” Actually, Theravada never had anything to do with the early Mahayana versus Hinayana squabbles. As far as I know, neither of those early feuding schools are even extant.
The original dispute. IMO, was not over the validity of the Buddha’s teachings, as our Dharma Friends commonmortal, hello, and wonder suggest, but over the interpretation. Unfortunately, the refutation of one distortion eventually created another distortion, one that was maybe more egalitarian and anti-intellectual.