You do have to be in Parliament, you just don't need to be an elected MP in the Commons.
Once upon a time it was the usual practice for the PM to be from the Lords, but in modern history that seems very unlikely to ever happen again. In principle (though this certainly was not how it was done historically) you could elevate somebody of your choice to become a Life Peer, just so that they can be PM.
When I say this wasn't done, I mean Life Peers didn't even exist until relatively recently, so back when "Lets have Lord So-and-So as PM" made sense they were a Lord for life anyway, typically because their father and his father and so on, the Life Peers are a new thing - created in the 20th century.