two surnames, the first one is the father's and the second is the mother's, is it possible thatCan I change my last name to my father's second, that is, the first one of my paternal grandmother?
My wild guess (consult a lawyer) is that if the name is somewhere on your passport you could convince them that that's the name that should appear in your Polish passport.
Otherwise, you'll need to go through the process in Spain (however that works).
Prsumably, the Polish idea would be that the very last name in your Spanish passport or on your national ID should be your 'nazwisko' in a Polish passport so you might need to get that squared with Spain before getting Polish documents (or change your name in Poland after you receive citizenship)