Is it immoral to advise PhD students in non-industry-relevant topics in middle-lower ranked universities? Currently, the situation in academia is that graduating from a top PhD program is almost a requirement for landing an R1 tenure-track job. However, many of these graduates will not end up at similarly top-ranked schools for their job, and as such are at middle to lower ranked schools.
At these schools, their research is generally still along the lines of what they did in their PhD/postdoc, and PhD students as such follow them, doing this sort of research. But some research fields have little to no industry relevance— a PhD student working in such a field at a middle to lower ranked school would have bleak prospects for academia, and also related industry jobs.
These PhD students as such often have to switch fields to stuff like data science etc. (often through self-learning in online courses) which are unrelated to their original field of research, or end up on a string of postdocs endlessly searching for a job. Many may have been better off getting a job right after undergrad and slowly working their way up.
In such cases, is it immoral to advise these PhD students?
While the question in the title is a good one, your post also makes some assumptions, in some cases dubious, which are really worth investigating first:

But some research fields have little to no industry relevance -- The truth is that almost all PhD research is highly esoteric and specialized, and unlikely to have any direct impact on industry. This is certainly true in my field (computer science), and probably true in many others to a greater or lesser extent. Why, then, do industry hiring managers even care that you got a PhD? Sometimes they don't, but often they value far more the qualities that having a PhD demonstrates, rather than the content of your research. For example: the ability to communicate well and sell ideas, the ability to solve technical problems, and the ability to dive deeply into learning what you do not understand -- these are fundamental skills gained during a PhD that are equally valuable in industry.
What I'm saying is: industry relevance of your PhD research is often not the top criteria for getting a good job; what matters far more is your general knowledge, technical skills, and communication and interpersonal skills.

These PhD students as such often have to switch fields to stuff like data science etc. Data science is a rare case where PhD research in data science appears to be valued in industry; most other PhD fields are not as valued in industry specifically, only generally. Do you suggest that all academics should just start doing data science? I think that would have some positives, but overall be a very sad world only motivated by money, rather than a true pursuit of scientific knowledge.

Many have been better off getting a job right after undergrad and slowly working their way up -- This is absolutely true, unfortunately. But do you also believe that the only good reason to get a PhD is to get a job in industry? That premise is absolutely false. What we can do and should do: raise awareness and encourage people to get a PhD for the right reasons, rather than the wrong ones. If you are thinking of spending 5+ years on a PhD, it should be because you truly want to do it, and you love the research you are doing for its own sake.


To answer your last question:

In such cases, is it immoral to advise these PhD students?

It is immoral to be dishonest: to make the PhD students believe that their research will have direct practical relevance if it does not, or to lead them to expect a particular job in industry when they graduate which may be beyond their expected skillset.
To be sure, some professors are guilty of such dishonesty and immorality.
But no, it is not immoral to advise students in a non-industry-relevant topic, if the expectations are clear and the expected topic is of mutual interest. In fact it is one of the most beautiful and compelling parts of science, that we do not need to be constrained by what is currently practical in industry.