Look at the middle picture. you can clearly see hashis clone.

So im guesssing that gedo mazou was summoned in that cave before madara gave his eyes to nagato. But what about when nagato summoned the statue because yahiko died? it couldnt just vanish from that cave because Madara was still alive at the time and he was connected to the gedou.

But the question is:
How did madara got that hashis clone in to the gedou?