The UK does not elect a Prime Minister directly. Unlike presidential systems (such as France or Ireland), voters elect Members of Parliament. The leader of the party that can command a majority in the House of Commons becomes Prime Minister and forms a government.
nickkelly.blog
Some thoughts on Leadership Changes and Democratic Mandate in the Westminster Parliamentary system
Voters elect MPs, not a Prime Minister directly Governments are based on a programme agreed with the electorate Leadership can change if the parliamentary party determines it should The democratic mandate endures so long as the government retains the confidence of the House of Commons