Is it appropriate and useful to inquire if an open position has an internal candidate?
I assume that there are often-if-not-always internal candidates for open positions, in academia and outside. There are always students looking for Ph.D. slots, Ph.D. students looking for postdoc positions, assistant and associate professors looking to move up to the next level. (Same for non-faculty positions, but that seems OT.) Sometimes the people responsible for the position may not even know yet about such internal candidates, because they may not yet have sent in their application.

So the question probably rather is whether these internal candidates are already frontrunners. The professor may want his extremely productive Ph.D. student to continue in the postdoc slot but may need to advertise externally for some procedural reason. The department may want to continue a certain research specialization and plan on promoting the retiring professor's assistant prof. In such a situation, external candidates will need to be very convincing to win.

But: how often will the external candidate be told this? If the external advertisement is legally required, the hiring people may even open themselves up to litigation if they openly tell an applicant that they are only soliciting outside applications as a fig leaf.

On the other hand, the department may explicitly be searching for "new blood", so internal candidates may actually have worse chances than external ones. Which, again, nobody will tell you (or the internal candidate).

Of course, it makes sense to tap your network and see whether the grapevine can tell you more than official channels. However, this kind of information can be unreliable. So if you hear from multiple sources that a given position will be filled internally, it may make sense to not make the effort.

Thus: there will likely be internal candidates, but you will probably not know how good their chances are. If you are a good match for the position, go and apply. Don't worry about internal candidates. This is one part of the hiring situation you can't control, just like the mood of your interviewers. Giving up on an application because there is an internal candidate will be counterproductive in the long run.