The moral lesson in Oedipus Rex, as the other answers have indicated, is that it is impossible to escape one's destiny and a sin to try to do so.
In the Greek worldview, one of the worst sins a person could commit was to think he knew better than the gods. This is what Oedipus does when he attempts to escape his god-ordained fate.
One feels for Oedipus, as he is handed a terrible future. The prophets foretell that he is destined to kill his father and marry his mother. Most people would try to escape a future that has such terrible consequences for their parents.
Oedipus is trying to protect the people he loves, as he flees Corinth and the parents he thought were his birth parents. It cannot have been easy for him to leave behind everything he knew. Nevertheless, his pride or hubris is to think he has actually won against the gods. It seems never once to have occurred to him that the man he killed in the road was his father or that the woman, Jocasta, he married in Thebes his mother. He goes on complacently year after year thinking he has beaten the gods—until he is confronted with the plague in Thebes.
What the gods have decreed will occur, as the play illustrates: Oedipus, in the end, accepts that wisdom.