Local-global principles for generalized Fermat equations via stacks