The stories in the Puranas contain many incredible and hard-to-believe occurences. But they should not be interpreted as a nursery rhyme. Their language is Shakespearean and laden with great depth and meaning. We need to interpret these stories with a very refined state of mind.
The story goes that Parvati created a boy out of dirt from her body and appointed him to guard the doorstep. The first question that comes is how could Parvati, the Goddess Herself, have so much dirt? Parvati symbolizes the triguna - sattva, rajas and tamas. The entire creation is made up of trigunas. The dosha or imperfections that originate out of the triguna is an obstruction for the functioning of Prakriti. That was the boy that Parvati created to stand guard at the door. Shiva is Shuddha Chaitanya, pure consciousness. Like the sun does not recognize darkness and cuts through it, Shiva does not recognize dosha and slays the impurity. But Prakriti cannot stay without impurity. So Shiva replaces the dosha with the head of an elephant, which symbolizes knowledge. Through knowledge, all the doshas or obstructions of Prakriti can be taken care of. This is the spiritual and metaphysical meaning of Ganpati being slain. So worshipping Ganpati as the remover of obstacles and the giver of gyana, knowledge is the most amazing depiction of the nature of consciousness.
Going a step further, even this difference between Prakriti and Purusha is done away with. That is why, the Ganpati Upanishad says,
ajam nirvikalpam niraakaaram-ekam
niraanandam aanandam advaita poornam
param nirgunam nirvishesham nireeham
para brahma roopam ganesham bhajema
Ganesha is the only One unborn unmanifest Reality. He is nirvikalpa and advaita - the formless, undivided One. This is the play and display of consciousness within itself.
While Ganpati is certainly the nirakara Parabrahman, he is invoked and worshipped in the mud idol for a period of time for the joy of the devotees. Then the Ganpati is asked to merge back into our heart and the idol is immersed in water. This ritual is observed for the sake of devotees, not for the sake of Ganpati. He who is without form is invoked in a form and then his spirit is invoked back into one's heart as the idol is immersed.