Why do some universities charge an application fee?
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.