The spectrum of a signal is its Fourier transform. Only sine and cosine signals have a "pure" signal with a single frequency. Anything else decomposes into a whole host of spectral contributions. Square waves are especially bad because they require contributions from infinitely many harmonics to produce the steep flanks. That is also why a clean square wave cannot exist: some kind of band limit is always present, resulting in ringing around the flanks.
Because you try to generate a square wave by adding toghether "round" waves (sinusoidal). In order to get into the "corners" you must add "round" waves with smaller and smaller diameters (period). Small periods means high frequencies. The more waves you add, the squarer the sum becomes.
See also Fourier Analysis on the Wikipedia article: https://en.m.wikipedia.org/wiki/Square_wave