Some (but not all) US consulates restrict application to persons that are residing in the country of application.
Whichever consulate you apply to, you will for sure need to prove that you are legally in the country at time of application either with a residence permit, a long-stay visa, an official citizenship proof (your passport), or other documents.
I don't know of countries that grant visas/residence permit to their own citizens, so if you apply under passport Y
, you will likely have no proof of legal standing in the country.
I can't find the form, but I doubt it doesn't have a question where you must declare all nationalities and ID documents received and you will likely to submit passport X
in complement of passport Y
, and that might play badly with the officer thinking why they would do that.
I suggest you to play it safe and either apply in X
with passport X
, or, if possible, at Y
with passport Y