Is it rude to ask whether a professor will leave by the time you're in the middle of research as a PhD student and you want to do research witht hem?
I would say it is not rude per se, but could be rude in implication. Rudeness always has a strong cultural component, though: what is rude in one culture may not be rude in another.
In the US, "you look/seem old" is rather rude. There is also an understanding that a PhD advisor would by ordinarily expected to supervise the entirety of a student's thesis project, and to not take on new students if they do not plan to commit to that. It's possible that the question you pose would appear like one of these accusations if it is not otherwise supported.
Assuming you have good reason to be concerned, though, I would recommend posing a question like this as about yourself and your career rather than the professor, and inquire if there are any time limits on supervision, or ask whether they will be able to supervise you for however many years is the planned duration of your degree. It is certainly suitable to ask about funding availability for the future if you are paid off of a supervisor's grants (e.g.: how many years of your expected PhD term is funding actually secured for), and to ask about any expected gaps in supervision like a planned sabbatical. "Is there likely to be any time during my PhD career that you won't be able to advise me directly, like a planned sabbatical?" might be a diplomatic way to raise the concern, and would be an appropriate question to ask of any professor.
It's a reasonable thing to want to know, so as long as you phrase the question in an appropriate manner, it should not come across as rude. Academics may leave a university due to retirement or due to other jobs at alternative institutions. This is common enough that it is something that should be considered (on both ends) when forming a supervisor/candidate relationship. I recommend you speak directly to your potential supervisor. To avoid rudeness, I would try something like this:
"One of the things I've been advised about when searching for a supervisor is to check to see whether you have any plans to leave the university in the next few years. I'm mindful of the fact that I'd like to have you as a supervisor for my whole candidature, but I don't want to be a burden if you have other life-plans that would make that difficult. If it's not too personal, would you mind telling me if there's any reason that you might not be able to support me for my whole candidature?"
No, it's not rude, but have a face to face conversation with them about your future and the possibility of working with them. Include and concerns such as this one in that conversation. Ask for their general advice on preparation and such as well.
Such a conversation can be very valuable for your future, but it isn't something to do by email.
If they are planning on leaving or retiring, they will probably give you hints at least, perhaps suggesting other people. But there are no guarantees as people can also take advantage of opportunities. Some students move along with professors who change institutions.