He summoned it back and sealed it in himself to keep himself living long enough to speak to the tailed beast. Unless you have another explanation?
No matter what we say...the true sequence of events will always be pure speculation.
but i'll go with what the manga gave us...
Hagoromo and Hamura used Rikudou chibaku tensei to defeat Kaguya creating a moon.
Hagoromo researched how to stop IT...resulting in him becoming Juubi Jinchuuriki (Either he summoned it from the moons core leaving the empty moon in space...or him doing this resulted in the first moons destruction)
After watching Ashura, Hagoromo found a new path and decided to create the Bijuu.
Having the Gedou mazou inside him allowed Hagoromo to cling to life due to it's powerful life-force.
When he was nearing death, Hagoromo extracted the mazo from himself and either used chibaku tensei to create a new moon...or reverse summoned it to an already existing moon.
Hamura took over the Ootsutsuki clan and migrated to the moon to watch over the Mazo