@rimi-some say the whole head repleacement thing happened beacuse Ganesha was only a creation of Prakriti(Parvati)
and every creation in this world has to have a bart of both Man and Woman-Purush and Prakriti
and hence by the beheading and Mahadev giving him life with an elephants head,he got a Purush element too
there are many versions of the story