In the United Kingdom, for example: Leadership elections are generally caused by the death or resignation of the incumbent (that is, the person already holding the post), although there are also formal and informal methods to remove a party's leader and thus trigger an election contest to find a replacement.
Leadership elections have great importance in parliamentary systems, where the chief executive (e.g.: a Prime Minister) derives their mandate from a parliamentary majority and the party's internal leaders hold frontbench positions within the parliament, if not outright serving in a ministerial post – whether as Prime Minister in the case of the leading government party, or another Ministerial post for junior coalition partners.
An electoral alliance, which is composed of multiple parties each with its own separate leader and organs, may also hold a common Prime Ministerial primary as in the 2021 Hungarian opposition primary, or a single party may wish to retain its leader but select someone else as its Prime Ministerial candidate, as the Portuguese Socialist Party has done in 2014.
In presidential and semi-presidential systems, the chief executive (the President) can only be removed by an impeachment procedure, which can only be initiated in specific situations and by a special procedure (typically involving a legislative supermajority, an investigation by a constitutional court, or both), and removal entails either a snap election or automatic succession to office by a Vice president.
However, this is not entirely comparable to the parliamentary situation, as the majority and minority leaders of political parties in presidential systems are not the chief executive of their country (as a prime minister would be), but are rather officers of the legislative branch of their country, a position similar to the floor leader (which similarly is a post subservient to the prime minister) of a political party in a parliamentary system which likewise doesn't hold mass enfranchised elections for such a post.