We vote for MPs, not Parties. The PM could lose their seat if their local constituency votes them out, even if every other person in the country voted for them. An example of that is the 1906 election [1], where Balfour lost his local vote and the Conservatives had to scramble to come up with a new leader. This is why top MPs are given safe seats by their respective parties. Of course, in practice, the vast majority of people vote for their Party not their local MP when they go to the polls during a general election. That isn't how the system is designed to function though. Most people couldn't even name their local MP - the one who is actually meant to represent their personal interests - which is an utter travesty and the source of most of this countries political woes.
[1] https://en.wikipedia.org/wiki/1906_United_Kingdom_general_el...