I don't know how it works everywhere, but I believe you would have to be officially enrolled at University X as a habilitation candidate.
This is not true in general.
Some universities make external candidate pay a large fee, others welcome external candidates, others (and this is relevant for you) demand of their external habilitands to teach an unpaid course at the university every couple of years to keep their "venia legendi" after the habilitation.
But isn't it true that you can never take a post at the university at which you do the habilitation, after finishing it? As in, that's the one school in the world you can cross off your list for a job ever, once you're done?
That's how it was explained to me by the people at X.
This is not true, either.
Usually, it is frowned upon to hire own PhDs immediately after graduation, but this is not a strict rule, either, it just costs your university some reputation if they do it, so you would really have to be worth it. The keypoint is that you are not supposed to have spent your whole career in one place, but that does not seem to be the case, anyway.
The details of habilitation depend strongly on your specialty and your university/region. You absolutely have to have reliable mentors in your specialty. (Where reliable = they are competent enough to tell you the truth and they are honest enough to tell you the truth if it is not in their interest to do so.)
Since you seem to want to be employed later by Y instead of by X, it is not comforting that X tells you that they won't employ their own habilitands, you need Y's opinion on it, preferably in the form of looking at recent hires. Depending on your specialty, they may not have habilitation at all these days.
I strongly suggest that you tell people at Y about your ongoing habilitation project at X, and about your career plans at the magnificent university of Y. They can hardly become your enemies because you have already started your project somewhere else and you should be able to gauge from their reactions whether they expect you to change something.
Unfortunately, I do get the impression that the people at university X like you, but are not necessarily acting in your best interest.