Well, the PM is appointed by the Queen, and is usually the leader of the party with a majority in the House of Commons, whom they send to HM with a request for authority to form her next government.
In the past, PM's have been members of the House of Lords, the Duke of Wellington being the example that came to mind but there were plenty of others.
The last example was Alec Douglas-Home, who became PM on 19/10/63, resigned his Earldom on 23/10/63. He had already resigned from the House of Lords in 1962 and was not an MP.
So for 20 days he was PM while not a member of either the Commons or the Lords. He stood for the vacant seat of Kinross & West Perthshire. Parliament's meetings were postponed until after the by-election, which he won. It would have been interesting if he had lost.
But it seems the law does not demand that the leading party's candidate for PM be either a Lord or MP.
Might just suit that chancer Farage.