Just saw a theory on YouTube and decided to develop it the way I like. It essentially says that the God's Knights will arrive at Impel Down to recruit Doflamingo, who was originally eligible to become one of them.
Elbaph Arc: The God's Knights Defeat
After failing to recruit Loki and having to kidnap the giant children, the God's Knights will have to join the battle in order to avoid Elbaph's destruction. However, they can't fight Loki, the Straw Hats and the giants all at once, so they'll wait to move on the aftermath of the battle, taking the opportunity to subdue a Yonko crew and the strongest country.
However, their plan is frustrated because, once Luffy defeats Loki and they move to join the battle, Shanks, who was out of the island dealing with Bartolomeo, arrives to fight his brother. In the meantime, Nami and the giants feed Luffy, letting him join the battle again. Seeing the alliance of 2 Yonko crews against only 4 God's Knights, Shamrock will shamefully retreat.
The Heavenly Demon is Freed
After their shameful failure on Elbaph, Shamrock arrives at Impel Down's Level 6. Tsuru recognizes him and is surprised that a God's Knight is there, but he demands to talk to Doflamingo. Once he says that, a maniac laughter is heard. Doflamingo jokes with Shamrock, who just ignores him and proceeds to invite him; Doflamingo, however, demands to become the God's Knights Commander,
Shamrock, annoyed with Doflamingo's arrogance, tortures him. He then comments that those with Supreme King Haki are stubborn, remembering Loki's refusal. To avoid death, Doflaming threatens to reveal what the Mary Geoise's National Treasure is to all the Level 6 Inmates, to which Shamrock replies he would simply kill everybody to keep the secret safe.
Reaching a dead end after failing to blackmail Shamrock, Doflamingo finally accepts joining the God's Knights, though not as their Commander.