Because in many parliamentary systems, the prime minister is not directly elected by the public. Voters elect members of parliament, and the party or coalition with majority support in the legislature chooses the PM; if the current PM resigns, their party can pick a replacement who can then be appointed if they still command that majority’s confidence.

Why it is legal

The legal idea is simple: the head of government needs the support of parliament, not a separate nationwide PM vote. In the UK, for example, a new prime minister is selected through the governing party’s leadership process and then appointed based on who can command confidence in the House of Commons.

Why people say “nobody voted for them”

People usually mean nobody voted for that person in a direct PM election , because there usually isn’t one. But voters did vote for MPs and, indirectly, for the party system that makes this possible, so the new PM still has democratic legitimacy through parliament.

What happens after a resignation

A resignation does not automatically trigger a general election. The ruling party can choose a new leader, the monarch or head of state appoints that person in some systems, and the new PM continues only as long as they keep majority support.

The practical tradeoff

This setup is legal because it keeps government continuous and avoids forcing an election every time a leader quits. The downside is that it can feel disconnected from popular voting, which is why these handovers often spark public frustration and debate.

In one line

So the answer is: they are not being “put in” by ignoring democracy; they are being selected under parliamentary rules that let the majority party replace its leader and keep governing.

TL;DR: In parliamentary systems, voters choose MPs, MPs support a government, and the PM is the leader who can command that support. When a PM resigns, the party can replace them without a new election unless parliament loses confidence or an election is otherwise called.