Because you cannot “rearrange the succession so that Margaery’s children could come before Cersei’s.” Three hundred years of precedent establishes that the oldest legitimate male child inherits. Absent an accusation of incest, there is no legal reason for Joffrey to be disinherited.
Not only would there be a civil war, but Margaery’s children will be seen as the Blackfyres come again and Joffrey as the wronged party, and Robert himself would be seen as a second Aegon the Unworthy.
As for why not reveal it first – after getting rid of Cersei, Robert could choose to marry anyone, and there’s no guarantee that he’d go for Margaery Tyrell explicitly. There’s also the possibility that Robert dies untimely and leaves Stannis as the openly acknowledged heir.
As I saw it, the point was to win his heart and loins first so that he’s got a strong spur to end his marriage and marry Margaery, then reveal the evidence of Cersei’s incestuous adultery so there’s a clear legal reason for why Cersei’s children are disinherited, and so that there’s no question about the legitimacy of Margaery’s kids.