So yes, a PM can just quit. There doesn't have to be an immediate replacement, cos we don't actually have to have a PM.
Although there will generally be either a leadership contest and/or the PM will announce a departure date to allow the replacement to fill in the paperwork in time to make it seamless.
But it's all still technically down to the monarch, who can appoint, or not, any MP they wish (in theory).