Why is lord Ganesha worshipped first before any puja?
Here's the story of its origin.
Shiva Bhagwan left his abode on Mt. Kailas in the Himalayas to meditate in a cave. Parvati’s friends suggested that she should have an attendant (gana) of her own because they were not pleased with Shiva’s ganas.
Thus, she used her divine powers and bore a son. She named him Vinayak and instructed him to guard their home.
When Shiva returned home, Vinayak did not allow him to enter. After a brief argument, Shiva beheaded Vinayak with his trishul. When Parvati heard about this incident, she cried in despair over the loss of her son. As a means to console Parvati, Shiva sent his men to the forest and instructed them to retrieve the head of the first living creature they met.
Shortly, his men returned with the head of a baby elephant. With his divine powers, Shiva placed the baby elephant’s head over his son’s body. In a matter of seconds, Vinayak came back to life.
After this incident, Vinayak became known as Gajaanan, which stems from the root word ‘gaj’ meaning elephant.
Shiva blessed him with a boon and explained that people would first offer their love and devotion to Ganeshji before starting any auspicious activity.
The story comes from brahma-vaivarta purāṇa (third part - Ganesha Khand)
Reference - Apna Prerak Parvotsavo book
Note: “The question: Why is lord Ganesha worshipped first before any puja?” is licensed by Stack Exchange Inc (https://hinduism.stackexchange.com/); user contributions licensed under CC BY-SA.