(A) They had the good sense to keep their knowledge under wraps. They didn't preach or proselytise or set themselves up in opposition to orthodoxy (as the Cathars did) but guarded what they knew with fearsome initiatory rituals. There was little chance of it seeping out to challenge the power of the ecclesiastical establishment.
(B) They kept on the move- travelling to where the work was- thereby slipping between the pillars of the feudal system. Nobody owned them, nobody was responsible for them.
(C) The Church needed them. If you burned all the masons who was going to build you your cathedrals?
(D) Many senior churchmen were secret sympathisers- fellow initiates, students of the mysteries. Orthodoxy was for the masses (to keep them in line); educated people knew better.