The paper is concerned with the electromagnetic scattering from a large cavity embedded in an infinite ground plane, which is governed by a Helmholtz type equation with nonlocal hypersingular transparent boundary condition on the aperture. We first present some stability estimates with the explicit dependency of wavenumber for the Helmholtz type cavity problem. Then a Legendre spectral Galerkin method is proposed, in which the Legendre--Gauss interpolatory approximation is applicable to the hypersingular integral and a Legendre--Galerkin scheme is used for the approximation to the Helmholtz equation. The existence and the uniqueness of the approximation solution are established for large wavenumbers; the stability and the spectral convergence of the numerical method are then proved. Illustrative numerical results presented confirm our theoretical estimates and show that the proposed spectral method, compared with low-order finite difference methods, is especially effective for problems with large wavenumbers.