Is there a way to remove scratches from glasses and sunglasses?

Usually not. Sometimes glasses can be buffed but generally, scratches you can feel with you fingernail means the lens needs replacement.
Sometimes. If the plastic lenses have very fine superficial scratches, an optician can often buff them out for you. Check with a reputable optical department and have then inspect the lenses to determine what can be done.
Not really. Next time you get new glasses, you can ask about which material for the lens is most scratch-resistant and/or adding scratch-resistant coating.