One night Ganesha was riding home on his mouse after a feast of modaks at his devotees' homes. Belly full, heart content.A snake crossed the path; the mouse jumped in fright and Ganesha tumbled down. Up in the sky, the Moon burst out laughing.Ganesha cursed: whoever looks at you shall be falsely accused. The Moon begged pardon, and the curse shrank to one night a year.They say Krishna too was falsely accused over the Syamantaka jewel after seeing this moon. So that night no one looks at it.
Source
Skanda Purana, Ganesha Purana; the custom — folk tradition