Sasuke used his godly power to decide the attack was a time machine instead of an attack, and it sent him into the future. He then donned an orange mask, become Tobi, went even further back in time, and got Obito to pose as Tobi while he ****ed shit up in the shadows, then let Obito be the fall guy for it all.