Two-loop beam and soft functions for rapidity-dependent jet vetoes