I have read of two different theories that explain why Ganesh ji is worshiped before any puja. Both these stories are also linked to the story of the birth of Ganesh ji.
Probably the most common story of Ganesh ji's birth is the story of his creation by Parvati devi so he could guard her palace in Mount Kailash.
As Parvati devi was taking bath, Mahadev Shiv ji returned home but was stopped from entering the palace by Ganesh ji who wanted to protect the promise he had made to his mother Devi Parvati.
Angered by Ganesh ji's challenge and unaware that he was Devi Parvati's son, Mahadev Shiv attacked Ganesh and destroyed his head. Later, when Parvati ji realized what had happened, she was angry and threatened to destroy the world. She declared that she would stop her rampage only if Ganesh was brought back to life and then declared as equivalent to the foremost Gods.
Realizing his folly, Shiv bhagwan offered to correct his mistake and requested Vishnu ji to fetch the head of the first living creature facing in the north direction that the latter spotted. This happened to be an Elephant.
Soon after, Ganesh ji was brought back to life with an Elephant head by Shiv bhagwan and was declared to be the foremost Hindu God who was to be worshiped before all other Gods. As a result, Ganesh ji is worshiped at the beginning of every puja till date.
This version of the story talks about the demon Gajasura (Elephant headed demon) who after painful penance to Shiv bhagwan was granted an armor that nobody in the world could destroy. Gajasura went on a rampage torturing the residents of the planet and slowly beginning to challenge the Gods.
He also continued with his penance to Shiv bhagwan who once again offered to grant him a wish. This time, Gajasura decided to play a trick on Shiv bhagwan and requested the latter to take residence in his stomach. Unable to see through Gajasura's trickery, Shiv bhagwan agreed. (this is also why Shiv ji is called Bhole-nath i.e. a simpleton who is unable to see through tricks).
When days later, Parvati Devi was unable to track her husband Shiv ji, she approached Vishnu bhagwan for help. Vishnu ji being omniscient knew what Gajasura had done and so he disguised himself as a comedian with Nandi (the follower of Lord Shiva) transformed as a bull.
Vishnu ji, in his disguise, and Nandi approached Gajasura and performed a comedy play for the latter. Pleased by the entertainment, Gajasura looked at Vishnu ji in disguise and offered to grant any wish that the latter asked for.
Taking advantage of this, Vishnu ji asked Gajasura to free Shiv bhagwan from his stomach. At this moment, Gajasura realized that the performer had to be Vishnu ji because nobody else could have known that Shiv bhagwan was locked in his stomach.
He agreed to free Shiv ji by tearing his stomach but in return asked Vishnu ji and Shiv ji to grant him another wish. He requested that he be remembered by all residents of the earth for eternity and that they all worship his face.
To grant his wish, Shiv ji called his son Ganesh and replaced his head with that of Gajasura. Further, Shiv ji declared that Ganesh be worshiped before all other Hindu Gods thus ensuring that Gajasura's name continued to be remembered by one and all for eternity.
As a result, Ganesh ji is worshiped before every puja as a fulfillment of Gajasura's wish to Shiv bhagwan.
Reference: Stories of Ganesh ji