I am writing a story and I want to know how much of a time gap was between the arrests of Queen Margaery of House Tyrell and Cersei of House Lannister.
The timeline in the show is unfortunately extremely vague so the official answer here is we do not know. This is also true in the books and as the show is based on the books it isn’t hard to see how the same ideas passed through. George R. R. Martin has said the following on the matter.
The reason I am never specific about dates and distances is precisely so that people won't sit down and do this sort of thing.
My suggestion would be to put away the ruler and the stopwatch, and just enjoy the story.
That said it can’t really have been much time between the events. The episodes take place chronologically per location and these events happen on back to back episodes. Both in Season 5 with Margaery being arrested in Episode 6, "Unbowed, Unbent, Unbroken", and Cersei in Episode 7, "The Gift".
In the latter episode before Cersei is arrested she goes to she Margaery in her cell. We also get to see her there and she isn’t quite as worn down or “rough looking” as we see when she has been in there for sometime; she mainly just looks unkept. As such there was likely only a couple of days to a couple of weeks between the two events.
The timeline in the books is even closer together as it all happens in the same chapter inside of A Feast For Crows, “Cersei IX”. The summary on A Wiki of Ice and Fire does a good job of explaining what happens in this chapter so I’ll copy it over but long story short is that Cersei is arrested a day or two after Margaery.
Accompanied by six newly reinstated Warrior's Sons, Septa Moelle brings word to the court that Queen Margaery and her cousins have been imprisoned at the Great Sept of Baelor for adultery and high treason.
The next morning, Cersei and Taena are carried by litter to the Great Sept.
Furthermore, he confesses that Cersei ordered him to kill the old High Septon. Upon hearing this, Cersei bolts from the cell, racing headlong through the Great Sept. Fearing what may happen should the Faith question Taena Merryweather, she is soon overtaken by a group of septas, who strip her and confine her to a grim cell.