A party can change its leader as many times as they like - it is only tradition that means the PM is the leader of the biggest parliament, it is not law - The King (I just wrote Queen and had to delete) can choose who ever he wants to be PM. The only stipulation is it has to be the person who can manage the majority of MP's.
I think this is an important point that a lot of people don't understand.
Both Boris and Truss failed in the end because they could not control or satisfy the MPs. That's what the PM has to do - have the confidence of the MPs to lead the house.
If he or she can't, the party can try a new leader, and if there is no one who can lead, then you get a GE.
That's how the system works, and as much as it may seem unsatisfying I am not convinced that any others work better, and many are clearly worse.