1. Win the majotrity.
2. House Dems (holding the Majority) can vote for a different Representative to be the Speaker. She was *their* choice. Not sure i it’s tied to an election cycle, a session, or just that the majority of the party wanting to take a new vote by fiat. But yes, she can be replaced/demoted from Speakership...by the Dems..if they wanted to.
Every January following an election the new Congress votes for their leaders. If Dems take a beating in November, chances are good Pelosi won’t be their leader come January.
Speakers are elected by the majority caucus at the time when the new Congress is being organized.
That said, the Democrat caucus is free to change their leadership at any time.
One suspects that a future minority Democrat caucus may wish to festoon the nearest lamppost with their current leadership.