Usually the phrase is 'at gaze.' But we find a verb (now obsolete) agaze=to frighten. In a-gape the a is = 'on.' But the similarity of sound in this, and in the phrase 'set them a-gazing ' may have led to the occasional introduction of the indefinite article.