Quantum phase transition triggering magnetic bound states in the continuum in graphene