One of the purposes, in regard to Greek mythology, is elevating human dignity, which leads to humanism.
In the Trojan war, the gods are portrayed as petty and squabbling, where Hector, in particular, is portrayed as selfless and honorable. The poem begins by invoking the goddess "Sing, Goddess of the..." but is focused on the rage of Achilles, not the gods. The poem ends with "the funeral of Hector, breaker of horses", one of the saddest lines in Western literature, meant to evoke pity.
In Christianity, this is much more direct--God becomes man in the person of the Christ, and Jesus' teaching lead to Western religious humanism.
Ancient Greek humanism, by contrast, arises out of questioning the gods, and even the legitimacy of the idea of the gods (Thales, Xenophanes, and others.)
The original purpose of the foibles of the Greek pantheon was probably entertainment value, with some allegory thrown in. (Bards have to sing for their supper, and if the stories aren't entertaining, they don't eat.) TheGods behaving badly and acting foolishly is highly entertaining! These stories were, and continue to be, popular.
The subversive nature of these stories was clearly recognized by later authors and philosophers, and utilized to undermine received wisdom, traditions and established beliefs.