Why Did Ganesha Give a Demon a Boon?
The Mudgala Purana tells of eight avatars of Ganesha — each one for a demon within.
Get the Mythraan app — freeGet the Mythraan app — free · App StoreThe katha
This demon did penance to Ganesha himself — and Ganesha himself gave the boon. And after that boon, no weapon could even touch him. The Mudgala Purana says Mamasura was born of Parvati's laughter. Mama means mine — a grip that never lets go of anything.
Earth, underworld, heaven — he put a lock on them all. Even the gods could not escape his grip. And Ganesha could not break a boon he himself had given. Then Ganesha came — Vighnaraja, the king of obstacles.
Vighnaraja simply let fall a lotus — and the army fell senseless. The boon guarded against weapons, not fragrance — and for the first time Mamasura's fist opened. The seventh name in the Sankatnashana Stotra — Saptamam Vighnarajam cha. The seventh of eight forms.
Each form, for a demon within. The last demon is the oldest — the I inside all of us.
Source
Mudgala Purana (Vighnaraja avatar); Sankatnashana Ganesha Stotra (Narada Purana)