Yoda knew he couldn't defeat the Sith. He didn't have the experience, the mindset, or the skill to beat the Sith. The novelisation shows us the moment that he realised this:
There came a turning point in the clash of the light against the dark.
It did not come from a flash of lightning or slash of energy blade
It came as the battle shifted from the holding office to the great Chancellor's Podium
It came when Yoda found himself alone against the dark.
Finally, he saw the truth.
This truth: that he, the avatar of light, Supreme Master of the Jedi Order, the fiercest, most implacable, most devastatingly powerful foe the darkness had ever known...
He'd never had it. He had lost before he started.
He had lost before he was born.
The Sith had changed. The Sith had grown, had adapted, had invested a thousand years' intensive study into every aspect of not only the Force but Jedi lore itself, in preparation for exactly this day. The Sith had remade themselves.
They had become new.
While the Jedi-
The Jedi had spent that same millennium training to re-fight the last war.
The new Sith could not be destroyed with a lightsaber; they could not be burned away by any touch of the Force. The brighter his light, the darker their shadow.
So even if Yoda had been able to kill Sidious, he would not have destroyed the Sith. The old Jedi way just wouldn't work to defeat these new Sith. They needed a new approach, one that he couldn't come up with while bashing away at Sidious with a lightsaber.
So he fled. He lived to train the Jedi who could defeat the Sith. He played the long game, just as the Sith had. And he lived to complete the training of Qui-Gon and the Force priestesses, to become "more powerful than [Vader] could possibly imagine".