Why didn't Madara use Izanagi to counter Kaguya? I know, this would have been a different story, but when Black Zetsu impaled Madara, Madara could have used Izanagi because he still had the Sharingan, as I know he can switch.
First, Madara always believed himself to be completely invincible. When Black Zetsu stabbed him, he could not even realise that he was being betrayed; it was completely out of his expectation. And it only took a very short period of time for Zetsu to gain complete control of his body.

Second, a huge weakness of Izanagi is that, it has be activated first. It is not a reset jutsu. It only can manipulate everything that happens between its activation and Sharingan going blind