If there were reliable ways to avoid being lied to in any kind of situation, we wouldn't need laws against fraud, catfishing wouldn't exist, there would be no spam, etc. The best you can do is play the hand which you are dealt.
Use the discrepancy as leverage. Presumably, the hiring manager is also your reporting manager, and so they are the person who told you one thing and is now asking you to do another. So you have a history doing X, they assume you are good at X, they know you hate X and would never have accepted the job to do X, but here are you doing it anyway. If you quit now, it looks bad all around. If you roll over, you lose all life satisfaction. So don't do either of those things. What you need to do is turn the situation you have into the situation you want, and that requires some effort and investment.
First, do X. Do it well. Do it so well you impress the heck out of everyone: your boss, your coworkers, people on other teams who don't know you directly, but just hear about how awesome you are at X. This builds your credibility, which means "political capital." Once you have proven that you are a valuable asset to the team and company, you will increase your ability to make demands. But it will require maybe 6-12 months of solid investment (read: sucking it up) to reach this point. Obviously, this is only worthwhile if the company is a place worth working at for several years (say, 5 years minimum).
Even though your boss has asked you to do X, on your very first meeting, you should voice your displeasure: "I specifically told you that I wish to do Y, not X. I understand you need me to do X, and I'm going to do that, despite your unethical misdirection. But I'm so good at X, that I'm going to do 100% of the average worker's effort in only 80% of the time. The remaining 20% of my time, you will give me projects involving Y. Over time, I will demand that my workload transition towards 100% Y, but I understand that this will be contingent upon my performance on X. If you fight me on this, I will shop around the other teams in the company and find a manager willing to let me work on Y. I hope we can come to an agreement."
The statement above might seem overly bold, but it is not. The manager is lying about X because they are desperate and nobody they are looking at wants to do X. That's the only reason they would risk lying about the position in the first place. They think you are also desperate, which is why you have been doing X all this time instead of Y. They know you must have some competence in X, or other companies wouldn't have had you doing it in the first place. And they know they can dangle Y in front of you as an enticement to do X. So let them. This is the game, and you have to play it.
But, you also need to recognize whether you are holding an unmatched 2, 6 or pocket aces. If you are really above-average at X (which you need to be for this strategy to work), then your new manager needs you more than you need them. This is why you can make demands. If they are reasonable, they will recognize that you are both an asset and a threat, and they will play ball to get what they need and keep you motivated. If they respond badly, then they are just a bad actor all around, and you don't want to waste your career working for such a person. You should just quit immediately, and ask HR for an exit interview, in which you explain that you were assured work on Y, but were asked to do X instead. This will put the hiring manager in a tough spot, because now others in management will know this manager is giving the company a bad reputation in the potential-employee marketplace. And if that doesn't happen, then the entire company is full of bad apples, and you want to run away from there as fast as you can.
If your title implies you do X, tell your boss that you want a title change that reflects Y, along with the relevant compensation. This might cost the manager a bit, but make it clear that they are not going to get what they want unless they meet you halfway, and this is part of the cost of lying about the position. This is important, because you want other folks in the company who look you up in the contact database to see that your title matches your aspirations, and not the drudge work you got stuck with. If there is no difference in titles between X and Y, then you're golden.
Finally, getting the work you want is similar to getting a promotion: don't wait to get promoted to do the work at the next level. Do the work at the next level, and use your competence to argue that you are already operating at that level, and the promotion is simply a recognition of that fact. The same logic applies here. Do as much Y work as you can independently. This includes things like subscribing to relevant internal mailing lists where people discuss Y, going to talks/events relevant to Y, networking with other folks doing Y, finding out the hot opportunities elsewhere in the company involving Y, etc. Basically, participate in Y as much as you can, within the scope of your actual job.
Many employees think that their job is a rigidly defined box with precise boundaries specified by their job description and an employee handbook. This is nonsense. A job is more like a balloon which expands to fill the space allowed by managers, coworkers, company culture, and personal ambition. Two people with the same title and theoretical position can have vastly different scope and responsibilities, depending entirely on their particular team environment and personal actions. Do every little thing you can to make your job more like Y, even though your boss wants you to do X. As long as you are doing well at both, your boss will be happy and go along with it. They just need results, and eventually, you can likely both get what you want and need. But you will need patience and you will need to pay your dues for a while so the company learns what you are really capable of. Good luck!