Often it's because the constitution of their country states that a sitting President can't be brought up on charges - Mugabe is a very obvious example.
But don't worry, Yeltsin had Putin's back...
> President of Russia, ceased to carry out its mandate, has immunity. They can not be held criminally or administratively liable for acts committed by them during the execution of the President's powers
https://en.m.wikipedia.org/wiki/President_of_Russia