Why do some universities charge an application fee? In the high competition of admission in top universities, it is common that every applicant must send lots of applications to different universities/programs to get approval for a PhD program.

Some universities charge an application fee. Why? This hinders many potential applicants.

For a research position (research associate, postdoc, etc.), the job advertisement system encourage as many as possible applicants to send applications. This gives more flexibility to select the best candidate.

Why do universities stop potential applicants for PhD applications with an application fee?

If the application fee is US$100, charging US$10,000 for 100 applicants is nothing for a university, but sending 10 applications ($1,000) is something for a student (particularly if coming from developing countries).

WHY do Western universities charge a small application fee, which is probably one month salary of a candidate from developing countries?
A system where everyone applies everywhere is not in the interest of any of the participants. Handling the applications requires significant effort on both sides and the applications are less meaningful. In particular, plenty of people will receive multiple offers inevitably turning all but one down. That requires waiting lists etc. In the end, some positions will even go unfilled.

In countries with a centrally-run system (for undergrad places: eg UK or Germany), this can be avoided on the central level. If there is no such system, then application fees are a means for the universities to encourage the applicants to send out only a small number of good applications.

That this disproportionally affects students from poorer backgrounds is an unfortunate side effect while the extra income is fortunate for the university.