No you don't have to remove the sunroof.
But yes if the foam has perished (very likely), you'll be scraping and scraping and scraping... There will be no point trying to re-glue to foam that's falling apart.
When you're putting it all back together, start with glue on the hardest surface (i.e. the board). You might get yourself some glue in a spray can to make that part easier.
For me personally, I'm probably going to start with a fresh new lining (I'm doing some reupholstering as part of my restoration project). So that's slightly less scraping and slightly more scope for cocking it up.