In terms of the purpose of Sophocles in writing the tragedy Oedipus Rex, we have no extant documentation. Although several plays by Sophocles have survived, we have no letters or diaries or even critical works in which he states his purpose in writing the play or even discusses the purpose of drama as a whole. The previous answer, alas, is based on Aristotle's overview of the nature of Greek tragedy rather than on any actual evidence about Sophocles' purpose or motives.
We have very limited information about Sophocles' life and ancient biography is notoriously unreliable. What we do know for certain is that Oedipus Rex was written for performance at the City Dionysia, a festival in Athens which honored the god Dionysus by presentation of several plays. Sophocles' other plays were performed at the festival of Lenaea that also honored the god Dionysus as well as the City Dionysia.
Each tragic performance included three tragedies and a comic satyr play by an individual poet and took place over an entire day. Many playwrights submitted scripts but only the best were actually performed, and those performed were awarded prizes of first, second, or third place. Playwrights earned considerable prestige by winning these competitions, but not money. Two other important reliable pieces of biographical background are that Sophocles served as a priest of Asclepius and that his family was wealthy.
Thus in terms of purpose what we can reasonably assume is that Sophocles, who wrote over a hundred plays in his lifetime, was motivated by:
- Piety: he was deeply religious and writing plays that were performed at religious festivals
- Enjoyment of writing: As there was no economic motive for him to write, and he was an extremely prolific poet, we can assume that he enjoyed writing.
- Prestige: Sophocles achieved substantial fame and honor by his writing.
Finally, for his choice of the story of Oedipus, there are two possible reasons for it. First, the traditional subject for Greek tragedies was the events that occurred in the heroic period that was assumed to be just after the Trojan wars; many Greek plays by different authors portray the Theban dynasty. Second, Oedipus was closely associated with Colonus, the small town near Athens where Sophocles and his family lived.
As to the purpose of tragedies themselves, they were part of the religious life of the city, presented to honor the god Dionysus. In terms of subject matter, they recounted a quasi-mythical history to an audience with only limited literacy and modeled civic and individual virtues, to a large degree by showing how vices led to disaster and having the chorus comment as a sort of moral compass on the choices of the main characters.
Greek tragedy is drama in which a tragic hero suffers a grave misfortune which is not accidental, but is meaningful in that it is connected reasonably with the hero's actions. Stressing the susceptibility of humans, tragedy portrays how man's suffering can instruct and entertain.
Tragedy stresses the vulnerability of human beings whose suffering is brought on by a combination of human and divine actions, but is generally undeserved with regard to its harshness.
And, although Oedipus is a Greek king from fifth century Athens, his tragedy speaks to many about integrity and altruism. As Jennifer Lewin writes in her essay, "Oedipus Rex: Possibly the Greatest of All Tragedies,"
Oedipus shows fearlessness in the face of turmoil, and his unstoppable quest for public utterance of the truth of the oracle leads him, tragically, to the knowledge that he has fulfilled its terms.
Sigmund Freud notwithstanding, Oedipus instructs readers that a certain integrity with excessive pride can unfortunately, lead to fatal results. Yet, even with his hamartia, Oedipus is admirable in his honesty and sincere intentions to help the people of Thebes. And, with his tragic knowledge about himself, there is in Oedipus an increase in wisdom. Thus, there is what Aristotle calls "catharsis," an emotional release as well as a renewed sense of the potentialities of human greatness at the end of the drama. For, it is the inner strength of Oedipus from whom many learn and are inspired.