Oedipus Rex encourages respect for the gods by showing what happens to a proud man who believes he can outwit the gods' will as expressed through prophecy. In his pride, Oedipus believes he can avoid the prophecy delivered by the oracle of Delphi, the mouthpiece—so to speak—of the god Apollo. When he learns his fate is to kill his father and marry his mother, he decides not to return home to Corinth and goes to Thebes instead. Ironically, it is precisely this decision that leads to the very fate Oedipus is trying to avoid (he doesn't know he was adopted by the monarchs of Corinth and that his birth parents are the rulers of Thebes). In showing Oedipus is unable to escape the prophecy, despite his best efforts, Sophocles conveys the idea that the gods' will must be respected above all other things.
Likewise, the main function of theatre in ancient Greece was to celebrate the gods. The first drama festival was actually a way to glorify the god of wine, Dionysus, and his festival was the only place that plays were performed for many years. Therefore, both Greek drama, in general, as well as Oedipus Rex, specifically, aimed to celebrate, offer respect, and pay homage to the gods.