The cavity resonance phenomenon has recently been suggested as an approach for regularizing the shear layer downstream of an aero-optic turret. Experiments on this geometry have been carried out in wind tunnels, with the cavity recessed in one wall. In this paper, we present a theoretical analysis which shows that this geometry can lead to an aeroacoustic mode-trapping phenomenon. The mode trapping arises when the cut-on frequencies fTcr for the tunnel cross-stream eigenmodes are higher than the cut-on frequencies fCT cr for the corresponding cavity-tunnel modes (in the region of the tunnel containing the cavity). Between these two critical frequencies, fCT cr < f < fTcr, there are frequency windows where mode trapping can occur. Because the acoustic radiation away from the cavity region is inhibited in these frequency windows, a cavity resonance field that involves a trapped mode can reach very high amplitudes, far in excess of the amplitude that would be found for the cavity geometry in an external flow environment. The theory predicts the characteristics of the cavity-tunnel and tunnel modes, and the frequency windows for aeroacoustic mode trapping, as a function of geometry and Mach number. Results of the theory are compared with experiments, confirming the importance of the mode-trapping phenomenon.