He was not elected by the general public to the position of Prime Minister. He was elected, by a small number of UK citizens in his constituency, to the Parliament seat.
British law doesn't even require the Prime Minister to be an MP, technically Parliament could elect any random bozo from the street to be PM.