It is not unusual for institutes to advertise positions (faculty or not) for which there is an internal candidate. In such situations, for external candidates, it may be difficult if not impossible to get in. When a position is advertised, is it appropriate and useful to inquire if a position has an internal candidate already? It might save a lot of time for the external candidate and possibly others (such as recommendation-letter-writers).
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.
I think it is only really useful if you know somebody at your target institution personally and are able to inquire "off the records". Formally asking a stranger whether an application procedure is just for show seems pointless - as Stephen says, the only realistic answer will be No, of course not.
However, note that your connection does not necessarily need to be somebody on the hiring committee. Oftentimes, it is enough to know another PhD student, who can then open his ears a bit for you. If there already is an internal "favorite" for a given position, this is often not really a secret internally. For instance, I have seen a case where, when the contract of a highly distinguished postdoc ended, a call for a assistant professor appeared out of thin air with a scope that looked as if it was copied and pasted (which it might actually have been) from the postdocs research website. From the outside, this might not have been insanely obvious, but internally, everybody knew who will be hired for this position.
It's usually a good idea to make some informal contact with the person offering the job before you submit an application. Send an email to briefly introduce yourself and maybe ask some questions (are there teaching opportunities for example). I've heard of cases where there will be a delayed or curt reply which may indicate that they're not interested in you. On the other hand if someone is genuinely looking for someone they are more likely to reply promptly and positively.