Why do gods do things which are not right according to dharma?
Accrording to saints like Sri Ramakrishna and Sri Sitaramdas Omkarnath, the exact meanings of scriptures has to be known by spiritual practice.The truth can not be known without sadhana.
Sri Ramakrishna used to say:
One has to do sadhana to understand the real meanings of the scriptures.Sugar is mixed with sand. Sugar has to be taken discarding the sand.
Sri Sitaramas Omkarnath says:
In purana, three types of language has been used. Laukiki (language of the masses),kavyiki(language of the poets) and of samadhi(to be understood by spiritual practice).
Let us take some ines from your source:
A tale in the Mahabharata (Book 13) narrates that Tilottama comes to tempt Shiva. Eager to see her as she circumambulated him, Shiva developed four visible faces.
Another interpretation states that Shiva revealed himself to Tilottama as the five Brahmans, with his five faces (4 visible, 1 invisible). The east face signifying his sovereignty over the world, the north face to sport with Parvati, the west to ensure the happiness of creatures; the south face, to destroy the universe and the fifth face was invisible as it was beyond the comprehension of Tilottama.
Another legend from the Puranas says Brahma created Tilottama and was aroused by her. Brahma lusts for his own daughter Tilottama and makes five heads in order to see her. Then Brahma sends Tilottama to Mount Kailash, the abode of Shiva, to pay her obeisance to him. Shiva glances at her, but avoids to carefully look at her as his consort Parvati was seated beside him. As Tilottama circumambulated Shiva, he develops a head in each direction to see her. The divine sage Narada taunts Parvati, "You can imagine what Shiva is thinking about this prostitute who is reviled by wise men". Agitated, Parvati covers Shiva's eyes with her hands submerging the universe in darkness. Shiva then develops a third eye to bring light to the universe.
So first we see there are various 'legends' and 'interpretations' indicating there must be some deep inherent meaning as opposed to directly narrating some incident.
We should also remember that creating faces or eyes tell of Their Divine Powers.So We must not use yardsticks of the mortal world to judge the activities of gods.
All what we know to be right are very much present in these scriptures.The lives of our great saints are shining proof of that.
Just to tell the real meaning in a roundabout way, such stories are created. In our culture, Vidya is Gurumukhi and so the right meaning of these can be learned only from Guru through sadhana.