I've learnt that a specific quantity is an extensive quantity divided by the mass. How does the definition of specific gravity fit into this scheme?
That's one definition of the term "specific quantity"; but the qualifier "specific" is used in other ways for other terms.
For example, Wikipedia's page actually gives plenty of examples of other terms using specific that don't rely on mass.
Basically, the definition of "specific quantity" that you use would not include the term "specific gravity", and that's perfectly fine, specific gravity doesn't have to be a "specific quantity", you just have to know that not every use of "specific" means per unit mass.
In this case, specific gravity is a term for the relative density of something compared to water.
One way of defining specific gravity is that it is mass of a substance divided by the mass (= specific) of an equal volume is water.