British Prime Ministers always leave office by resignation, unless they die in office.
If their party loses a general election, they resign, although not always instantly. Gordon Brown remained Prime Minister for several days after the 2010 General Election, because no party had a majority of seats, and it took time to form the Conservative-LibDem coalition.
May's situation is unusual, simply because it's rare for a PM to lose control of their party so comprehensively. The legal situation is that the Queen appoints whoever can command a majority in the Commons for a vote of confidence. If a party holds a majority, its leader is appointed PM. At present, no party has a majority, and it's not clear that anyone can command a majority.
May has resigned as leader of her party. The party will now elect a new leader, and May will then resign as PM, and recommend to the Queen that her successor as Conservative leader is appointed as PM. However, given the current membership of the Commons, it is not obvious that a new Conservative leader will be able to command a majority. This will have to be tested with a vote of confidence, and the Democratic Unionist Party from Northern Ireland will try to exact a high price for their support. Even if the new Conservative leader gets that, the situation is delicate.
There are 313 Conservative MPs and 10 DUP, making 323. There are 246 Labour MPs and 72 other seats held by opposition parties, making 318. That's not a solid majority. There are also 8 unused seats, one owing to the recall of an MP who will be replaced on 6th June, and 7 to which the Sinn Fein party of Northern Ireland were elected, but which they refuse to take. Clearly, the by-election to replace the recalled MP is going to be important. If the vote of confidence is not passed, there are fourteen days to pass one. If that is not achieved, then the Commons is dissolved for a general election.
The last time something similar happened was when David Cameron resigned as Conservative leader in 2016 after the EU Referendum, and the Conservative party elected May, who became Prime Minister without a general election. Cameron remained PM until May became Conservative leader and then resigned, recommending to the Queen that May should become PM.
The previous instance was in 2007, when Tony Blair resigned as Labour Party leader, the party elected Gordon Brown as its leader, and Blair then resigned as PM, with a recommendation to the Queen that she appoint Gordon Brown as PM.
Before then, John Major replaced Margret Thatcher in 1990, James Callaghan replaced Harold Wilson in 1976, Douglas-Home replaced Macmillan in 1963, and so on back into history. This is normal procedure.