The short answer? The composers of old with the largest surviving repertoires are considered “great.” Their works were viable, notated, and easily accessed by the public. Before the Renaissance, music notation was an inexact art (although one might say that that is still the case), and a lot of the music of the day wasn’t written down or otherwise preserved in a form that would ensure its longevity. In those cases, after a composer died, so did their music. There were many fantastic musicians whose music simply did not stand the test of time.
The long answer is a bit more complicated….
Mozart and Beethoven were musical geniuses and pioneers of their respective eras. Their music had public appeal because they adhered to social norms of the day and/or pushed the envelope of what was considered conventional, attempting (in Beethoven’s case, at least) “revolutionary” compositional approaches. Their popularity, combined with more lasting methods of music notation, ensured their music a place in the lasting repertoire.
Ironically, in the case of J.S. Bach, his music was largely neglected and forgotten after his death, due in part to the arrival of the Enlightenment (and by extension, Classical music). Audiences in the Enlightenment largely rejected the extravagant ornamentation and counterpoint of previous centuries. Music needed to have a purpose, a criterion which Bach’s music did not meet at the time. In the 1800s, a Baroque “revival” saw the return of Bach’s music to the public eye.
What classifies an artist as “great” is ultimately determined by a number of factors. As mentioned above, the criteria include:
They wrote a lot of music.
Their music survived after the composer’s death.
Their music was popular with the public during their lifetime.
Their music adhered to or directly challenged normal practices of the time.
Their music is still performed today.
It’s ultimately a very subjective matter. A composer need not satisfy ALL of the aforementioned points to receive distinction as one of the “greats”. It boils down to personal preference at the end of the day, but these are just a few things to think about.