Why did Shiva have an extra-marital affair with Mohini and beheaded his own son Ganesh by mistake like a human, being a supreme god?
When Rama, the incarnation of the god Vishnu, lost his wife, he did not get her back with supernatural, authoritative power. He had to fight for her (although he did many other things with supernatural power). In the battle, when his brother got injured, Rama was helpless until a sage prescribed a Himalayan plant for his treatment. Rama, though he was god, was helpless to procure the plant; so Hanuman flew to the Himalayas and got the plant. Sita, Ram's wife offered vows to Ganga while praying for Ram's safety. When Rama wanted to kill Bali, a bad guy, he had to use stealth because Vali had a boon that he could draw half his opponent's power to himself. Rama could not nullify this boon. Similarly, Rama could not prevent Ravana's 10 heads from rejoining themselves to his neck whenever Rama beheaded him. Being a supreme incarnation of god why he did he fail to do all these things?
Even in Mahabharata, Krishna behaves like a normal human being not using any supernatural powers. Why?
What was god's intention in doing all these things?
What is god's message to us from all his incarnations?
In answer to the first question, Shiva behaved that way because the stories were written at a time when men behaved that way and men at the time would have understood behavior like that.
In answer to the second question, when God incarnates in human form He is taking form in maya and therefore accepts the limitations of maya. God is limitless in the spiritual realm. Everything is limited in maya. When He takes birth in maya, He accepts the limitations of maya.
These are just myths created to explain the existence of specific 'God' or 'Energy' or 'Power' that affects human life. For instance the joining of Shiva and Mohini (actually a female form of Vishnu), creates a God with the qualities of both Shiva and Vishnu (worshiped in South India as Hariharputra). See here for an explanation of these myths (including that of Ganesha).
Rama and Krishna behave like humans because that is what they are. They are also incarnations of Vishnu, meaning the divinity of Vishnu has descended into them making them divine. However they still remain human. Krishna was a more of a God ('Sampoorna Avatar') than Rama, so he did not have as many difficulties or was as helpless as Rama during his lifetime. It is the same as asking, if Jesus was a God how did he allow himself to be tortured and beaten.
Gods intention in sending these Avatars like Rama and Krishna is to send them as teachers for humanity. Rama taught us as a role model of being a perfect human and Krishna taught us through his Geeta.
Like any library, Hinduism Stack Exchange shares great information, but does not offer personalized advice, and does not take the place of seeking such advice from any Acharya, Pundit, astrologer, Guru or other trustworthy Counselor.