Roddenberry apparently got the idea of Q after the main story involving the jellyfish aliens was developed. So the trial plot was probably quickly written and just shoved in there where it could fit.
Oh, definitely. But I think he was always meant to be a reoccurring since he appeared twice in the first season. The later writers developed the character and idea of his people as the show went along.