user6726's answer addresses the situation in the USA. In Germany, the situation is similar:
In Germany, the official criterion for a charitable organization is Gemeinnützigkeit (literally: "useful to the public"). If an organization is recognized as "gemeinnützig", it is exempt from some taxes, and can receive fines imposed in criminal trials.
In Germany, "Gemeinnützigkeit" is granted (and possibly revoked) by the revenue service (Finanzamt). The conditions are laid out in Abgabenordnung §52f:
Eine Körperschaft verfolgt gemeinnützige Zwecke, wenn ihre Tätigkeit
darauf gerichtet ist, die Allgemeinheit auf materiellem, geistigem
oder sittlichem Gebiet selbstlos zu fördern. Eine Förderung der
Allgemeinheit ist nicht gegeben, wenn der Kreis der Personen, dem die
Förderung zugute kommt, fest abgeschlossen ist, zum Beispiel
Zugehörigkeit zu einer Familie oder zur Belegschaft eines
Unternehmens, oder infolge seiner Abgrenzung, insbesondere nach
räumlichen oder beruflichen Merkmalen, dauernd nur klein sein kann.
A corporation shall serve public-benefit purposes if its activity is
dedicated to the altruistic advancement of the general public in
material, spiritual or moral respects. It shall not be deemed an
advancement of the general public if the group of persons benefiting
from such advancement is circumscribed, for instance by membership of
a family or the workforce of an enterprise, or can never be other than
small as a result of its definition, especially in terms of
geographical or professional attributes.
So in Germany a charity is allowed to pay its employees, including its CEO. However, it is not allowed to set it up in a way that only the employees, or only the CEO receive money - that would violate the second phrase.
Of course, there is a large gray area where the charity uses some funds for its stated purpose, and some (large) part as pay. Whether that is okay is an individual decision of the revenue service (and ultimately the courts), because it is hard to formulate a general rule about how much overhead cost is "too much".
In practice, the rules are usually:
- The work that is compensated must be required for the charity's stated purpose.
- The compensation must be "appropriate", i.e. more or less the usual market rate for the work.
- The compensation must be duly authorized. It must be permitted by the organization's bylaws, and approved by the appropriate people (usually also specified in the bylaws).
As an aside, in Germany, there is the "DZI-Spenden-Siegel", a certificate for financially responsible charities. One of its conditions is that spending for administration (including salaries) and advertising does not exceed 30% of revenues. It does not have legal force.