It depends what one means by democracy. The past couple of decades have seen the rise of illiberal democracy, in which the majoritarian mechanisms are more or less preserved, but there is a degradation of minority rights, separation of powers and so forth. To quote one of the opening paragraphs of the 1997 article by Fareed Zakaria, which popularised this [latter] term:
It has been difficult to recognize this problem because for almost
a century in the West, democracy has meant liberal democracy--a
political system marked not only by free and fair elections, but also
by the rule of law, a separation of powers, and the protection of
basic liberties of speech, assembly, religion, and property. In fact,
this latter bundle of freedoms--what might be termed constitutional liberalism--is theoretically different and historically distinct from democracy.
That democracy contains the mechanism of its own destruction, i.e. voting laws to effectively terminate it, as well as voting in people who would are willing to use such laws to such an effect, goes without saying... It's only a small corollary of that the "tyranny of the majority" can be exercised (and more often is) against minorities than in a collective act of surrendering power entirely.
As for what democracy means... despite the coloration of liberalism, it still primarily means what it always meant... (quoting Zakaria again):
From the time of Herodotus democracy has meant, first and foremost, the rule of the people. This view of democracy as a process of selecting governments, articulated by scholars ranging from Alexis de Tocqueville to Joseph Schumpeter to Robert Dahl, is now widely used by social scientists. In The Third Wave, Samuel P. Huntington explains why:
Elections, open, free and fair, are the essence of democracy, the inescapable sine qua non. Governments produced by elections may be inefficient, corrupt, shortsighted,
irresponsible, dominated by special
interests, and incapable of adopting
policies demanded by the public
good. These qualities make such
governments undesirable but
they do not make them undemocratic. Democracy is
one
public virtue, not the
only one, and the relation
of democracy to other public virtues and vices can
only
be understood if democracy
is clearly distinguished from
the other characteristics of
political systems.
This definition also accords with the
commonsense view of the term. If a
country holds competitive, multiparty
elections, we call it democratic. When
public participation in politics is increased,
for example through the enfranchisement
of women, it is seen as more democratic. [...]
Constitutional liberalism, on the other hand, is not about the procedures for selecting government, but rather government's goals. It refers to the tradition, deep in Western history, that seeks to protect an individual's autonomy and dignity against coercion, whatever the source--state, church, or society. The term marries two closely connected ideas. It is liberal because it draws on the philosophical strain, beginning with
the Greeks, that emphasizes individual liberty. It is constitutional because
it rests on the tradition, beginning with the Romans, of the rule of law.
Constitutional liberalism developed in Western Europe and the United
States as a defense of the individual's right to life and property, and freedom of religion and speech. To secure these rights, it emphasized checks
on the power of each branch of government, equality under the law,
impartial courts and tribunals, and separation of church and state. [...]
Only in the late 1940s did most Western countries become full-fledged
democracies, with universal adult suffrage. But one hundred years earlier, by the late
1840s, most of them had adopted important aspects of constitutional liberalism--the rule of law, private property rights, and increasingly, separated powers and free speech
and assembly. For much of modern history, what characterized
governments in Europe and North America, and differentiated
them from those around the world, was not democracy but constitutional liberalism. The "Western model" is best symbolized not by the mass plebiscite but the impartial judge.
Now, we'd be getting a bit philosophical on whether democracy (narrowly defined as above) "has a purpose" as you ask, or is it simply a naturally emerging phenomenon.
There has been a lot of empirical research on the determinants (i.e. conditions leading to) democracy. The "determinants" paper I've mentioned/linked is also instructive from a (political science) theory perspective on how democracy is quantified...
Numerous measures of democracy exist, including several new ones that draw on different conceptual schemes and methodological approaches such as IRT-modelling or machine learning (Pemstein et al. 2010; Gründler and Krieger 2016). We employ four widely adopted democracy measures. First, Democracy and Dictatorship (DD/ACLP Cheibub et al. 2010) has long been the most prominent minimalist democracy measure, categorizing regimes as democratic only if they have multi-party elections and incumbents have demonstrated willingness to concede electoral defeat and transfer power constitutionally to the opposition. We use updated data from Bjørnskov and Rode (2019). Second, the Boix-Miller-Rosato (BMR) measure (Boix et al. 2012) differs from DD/ACLP by evaluating factors other than governmental change to decide whether a regime is competitive or not, and by also requiring the granting of voting rights to the majority of male citizens so as to code a regime as democratic.
DD/ACLP and BMR are dichotomous by construction. In contrast, our third measure, Polity2 from Marshall et al. (2018) ranges from − 10 to + 10. Polity measures a more expansive concept of democracy than DD/ACLP/BMR do by incorporating executive-branch constraints, which, according to liberal understandings of democracy, is critical for avoiding abuses of power. We use the most common threshold and construct a dummy scored 1 if Polity2≥6 . Although the cutoff point admittedly is arbitrary (Cheibub et al. 2010), and other thresholds have been adopted (Bogaards 2012), our specification classifies the more ambiguous, and often controversial, cases as non-democracies. Finally, we use a categorical measure based on V-Dem data (Coppedge et al. 2019), namely the “Regimes of the World” measure in Lührmann et al. (2018), which we dichotomize (electoral democracies and liberal democracies are counted as democracies). To count as an electoral democracy, a country must pass three thresholds on indicators of multiparty elections ( v2elmulpar_osp>2 ), free and fair elections ( v2elfrefair_osp>2 ), and an Electoral Democracy index ( v2x_polyarchy>0.5 ). The resulting measure overlaps strongly (about 90% agreeement) with the three other democracy measures, but typically leads to fewer countries being classified as democracies (Lührmann et al. 2018, 68).
As you can see, the tension with [including or not] some feature of liberalism (in the sense of Zakaria) in the definition of democracy persists/exists at this operational level too...
In some models, democracy can be a little bit of both: a phenomenon that satisfies the interests of enough groups in some way, better than the alternatives, i.e. as a result of bargaining game of some kind, e.g. in Acemoglu and Robinson's (which is not necessarily the most empirically validated model):
A rise in inequality under autocracy increases the threat
of revolution by the poor. Elites weigh their gains from
continuing to set tax rates in an autocracy while continuing
to pay the costs of repression relative to their
gains from granting democracy and allowing the poor
(median) voters to set tax rates. For the poor, democracy
represents a credible commitment by the elite to
accept limited redistribution of income.
If you want more philosophical reasons for democracy (again defined narrowly)... SEP has a nice page on this, e.g.
Strategically, democracy has an advantage because it forces decision-makers to take into account the interests, rights and opinions of most people in society. Since democracy gives some political power to each, more people are taken into account than under aristocracy or monarchy. The most forceful contemporary statement of this instrumental argument is provided by Amartya Sen, who argues, for example, that “no substantial famine has ever occurred in any independent country with a democratic form of government and a relatively free press” (Sen 1999, 152). The basis of this argument is that politicians in a multiparty democracy with free elections and a free press have incentives to respond to the expressions of needs of the poor. [...]
Many have endorsed democracy on the basis of the proposition that democracy has beneficial effects on character. Many have noted with Mill and Rousseau that democracy tends to make people stand up for themselves more than other forms of rule do because it makes collective decisions depend on them more than monarchy or aristocracy do. Hence, in democratic societies individuals are encouraged to be more autonomous. In addition, democracy tends to get people to think carefully and rationally more than other forms of rule because it makes a difference whether they do or not. Finally, some have argued that democracy tends to enhance the moral qualities of citizens. When they participate in making decisions, they have to listen to others, they are called upon to justify themselves to others and they are forced to think in part in terms of the interests of others. Some have argued that when people find themselves in this kind of circumstance, they come genuinely to think in terms of the common good and justice. Hence, some have argued that democratic processes tend to enhance the autonomy, rationality and morality of participants. Since these beneficial effects are thought to be worthwhile in themselves, they count in favor of democracy and against other forms of rule (Mill 1861, p. 74, Elster 2002, p. 152).
I'm not sure as to the extent that these more elaborate theories can be or have been tested... The same page also notes some limitations (beside the well known critics like Plato or Hobbes) e.g.
Social choice theory questions the idea that there can be a fair decision making function that transforms a set of individual preferences into a rational collective preference. No general rule satisfying reasonable constraints can be devised that can transform any set of individual preferences into a rational social preference. And this is taken to show that democratic procedures cannot be intrinsically fair (Riker 1980, p. 116).
I'm not sure I buy the SEP classification of democracy's benefits in "instrumental" and "non-instrumental", but from the latter category they list:
Some argue that the basic principles of democracy are founded in the idea that each individual has a right to liberty. Democracy, it is said, extends the idea that each ought to be master of his or her life to the domain of collective decision making. First, each person's life is deeply affected by the larger social, legal and cultural environment in which he or she lives. Second, only when each person has an equal voice and vote in the process of collective decision-making will each have control over this larger environment. Thinkers such as Carol Gould (1988, pp.45-85) conclude that only when some kind of democracy is implemented, will individuals have a chance at self-government. Since individuals have a right of self-government, they have a right to democratic participation.
And indeed the page notes the obvious issue with the "from liberty" argument...
The trouble is that there is rarely agreement on major issues in politics. Indeed, it appears that one of the main reasons for having political decision making procedures is that they can settle matters despite disagreement. And so it is hard to see how any political decision making method can respect everyone's liberty.
A bit more elaborate, but also problematic is the argument "from equality"...
Many democratic theorists have argued that democracy is a way of treating persons as equals when there is good reason to impose some kind of organization on their shared lives but they disagree about how best to do it. On one version, defended by Peter Singer (1973, pp. 30-41), when people insist on different ways of arranging matters properly, each person in a sense claims a right to be dictator over their shared lives. But these claims to dictatorship cannot all hold up, the argument goes. Democracy embodies a kind of peaceful and fair compromise among these conflicting claims to rule. Each compromises equally on what he claims as long as the others do, resulting in each having an equal say over decision making. In effect, democratic decision making respects each person's point of view on matters of common concern by giving each an equal say about what to do in cases of disagreement (Singer 1973, Waldron 1999, chap. 5).
One difficulty is that this view relies on agreement much as the liberty views described above. What if people disagree on the democratic method or on the particular form democracy is to take? [...]
And in contrast to these it notes Schumpeter's elite theory of democracy (which is basically a game of competing elites, with the public sitting as judges)
Against the liberty and equality arguments, the elite theory simply rejects the possibility that citizens can participate as equals. The society must be ruled by elites and the role of citizens is merely to ensure smooth and peaceful circulation of elites.
In another bargaining-oriented view, but which doesn't single out any elites... Dahl's vision:
“In a rough sense, the essence of all competitive politics is bribery of the electorate by politicians… The farmer… supports a candidate committed to high price supports, the businessman…supports an advocate of low corporation taxes… the consumer…votes for candidates opposed to a sale tax” (Dahl 1959, p. 69). In this conception of the democratic process, each citizen is a member of an interest group with narrowly defined interests that are closely connected to their everyday lives. On these subjects citizens are supposed to be quite well informed and interested in having an influence. Or at least, elites from each of the interest groups that are relatively close in perspective to the ordinary members are the principal agents in the process. On this account, democracy is not rule by the majority but rather rule by coalitions of minorities. Policy and law in a democratic society are decided by means of bargaining among the different groups.
This approach is conceivably compatible with the more egalitarian approach to democracy. This is because it attempts to reconcile equality with collective decision making by limiting the tasks of citizens to ones which they are able to perform reasonably well. And it attempts to do this in a way that gives citizens a key role in decision making. The account ensures that individuals can participate roughly as equals to the extent that it narrowly confines the issues each individual is concerned with. It is not particularly compatible with the deliberative public justification approach because it eschews deliberation about the common good or about justice.
Although the SEP page does not elaborate much on this, it does note that underlying these theories is a theory of human nature... and that in reality there could be mixture of psychology at play...
Empirical evidence suggests that individuals are motivated by moral considerations in politics in addition to their interests. Accordingly, many propose that democratic institutions be designed to support the inclination to engage in moral and open-minded discussion with others.
Interestingly enough, a recent (and controversial) paper on the (inevitable?!) degradation of democracy has also attempted to argue from this behavioral/psychological perspective.
So, if you want theoretical justifications for democracy... opinions vary what the grounds for it should be. And yeah, entire books have been written on the topic. One that [encyclopedically] covers more or less the same material as the SEP page, but more extensively, is W. Nelson's On Justifying Democracy.
Mostly undiscussed in many of the theoretical works is the geographical scope of democracy... but this turns out to be related to its purpose, if we believe the more recent works in this regard, such as Marchetti's Global Democracy: For and Against. Quoting from a review:
Marchetti maintains that a
vast majority of the world’s population is currently in a similar situation as the minorities
are [...]: a state-based system remains ‘an unsatisfactory framework for the
self-determination of transborder interests such as those embodied by non-national or
transnational political agents including as [sic] migrants, people of transborder religions,
minorities and workers’). Marchetti concludes that ‘[i]f the phenomenon of transnational exclusion is to be eluded, current institutional arrangements need to be profoundly reformed’. The only system able to avoid transnational exclusions of the kind discussed is global democracy.
In fact SEP now has (newer) separate page on the latter topic...