Where? In the first available country of safe refuge because you're fleeing political persecution or war? Yeah, I'd say that's 100% legal and moral. That's how you get from Syria to Turkiye.
Is it legal and moral to then pass through 5 or 6 countries on your way to the USA or Sweden and request "asylum" because you want to find safe refuge in the country that has the best economic opporunity (or benefits)? How about buying a plane ticket from MENA to Mexico and then claiming asylum at the US border? Certainly the Mexican gov't isn't beholden to whatever dictator you were escaping in the Middle East. Could it be you're actually just abusing the asylum system to improve your economic outlook?
Mayyybe that abuse is legal, but if you want to say it's moral you'll have to answer to the millions of people who pay money, fill out the forms, and immigrate to the US legally in search of the same opportunities. My take on it would be that cutting the line isn't moral, but maybe your values differ.