I’ll get into this more when I get to ADWD, but it was definitely planned in advance. If you look at how Jon’s assassination went down, you don’t get that kind of Julius Caesar-style coordinated assault without prior planning, and no one knew about Jon’s planned march to Winterfell before he opened his mouth.
I believe that Marsh began planning his coup the moment Jon agreed to let the wildlings through the Wall, and I think his plan for survival was and is a coup, with either Marsh or one of his allies declaring themselves the 999th Lord Commander.