It was a sacrifice Yoda asked Palpatine to make a long time ago.
When they were young, when the Republic was young, when the prophecy was first made, when the Sith menace was still a public one, Yoda and Palpatine recognized that once defeated the Sith could never again be allowed to challenge the Jedi in that way again. Those were dark times.
The fall of Darth Plagueis was engineered by the two of them. Palpatine was to act as the Sith lord's apprentice. In this capacity, he betrayed and murdered the last of the great practitioners of the Dark Side of the Force. To prevent it from rising again, Palpatine was to assume the role of the Sith master, carefully cultivating for a thousand years generations of successors until the day the prophecy was to be fulfilled, a day both he and Yoda dreaded. They knew what must happen. They knew it would be the end of the Force as it had been practiced since sentient life first discovered its existence. It was not the loss of knowledge or tradition they feared, but the sacrifice that would be necessary, certainly Palpatine's but Yoda's as well. They were, in the end, friends first and foremost. Eventually, they would both have to die, one not living to see the day of victory and the other to die on that day as its hidden symbol.
The last time they directly collaborated was in the life of Count Dooku, who served as apprentice to both of them. Dooku was the catalyst for the creation of the last of the Sith, a role both Yoda and Palpatine were reluctant to place as a burden on someone else. It was Palpatine, finally, who insisted the plan reach its fulfillment, who reassured his two friends that he would accept what must be done, in the end, on his own.
In his final moments, Palpatine saw his life flash before his eyes, even before death came for him at last. It was old magic, something he'd picked up from his long tenure studying Sith lore. No one was left to mourn him. He would die the villain. But it would be worth it. Finally victory was attained.