How can I customize the header and footer from a custom page controller?
It depends on how you have built these. Generally you will set any blocks in the header and footer to only show on the paths they are meant to show on, in the block visibility settings. If you need completely different headers and footers altogether, you can build a new theme with those headers and footers, and create a custom theme negotiator (https://www.webomelette.com/choose-your-theme-dynamically-drupal-8-theme-negotiation) to set the theme for those pages.