You open in their language, they reply in English, and the conversation is over before it started. It happens to everyone and it is almost never rudeness — but knowing why does not help unless you also know what to do in the next three seconds.
It is usually efficiency, not judgement
They have somewhere to be, or they want to help, or their English is better than your Spanish and they are optimising for the transaction. In a shop or a station this is simply what happens. Very occasionally it is someone who wants to practise their own English on you. That is a fair trade, not an insult.
Answer the question they asked, in their language
The most effective response is not to protest. It is to keep going as if you had not noticed, and to answer fluently enough that switching stops being the faster option. Speed and confidence matter more than accuracy here. A quick imperfect sentence keeps you in the language; a slow correct one invites another switch.
Ask for it directly, once
One clear sentence works better than anything indirect: I am learning, may we speak in your language. Said warmly, most people agree immediately and stay switched. Say it in their language, obviously. It is also a demonstration that you can.
Change where you practise
Service encounters are the worst setting for this: the other person is being paid to be efficient. Conversations where the other person has time — a tutor, a language exchange, a neighbour, a hobby group — almost never collapse into English. If it keeps happening everywhere, the fix is not a better phrase. It is finding contexts where speaking slowly is socially fine.
Take the switch as information about the situation, not about your ability. Answer in their language, ask once, and spend your practice time where nobody is in a hurry.