Excitation of terahertz modes localized on a layered superconductor: Anomalous dispersion and resonant transmission