The harmonics of a square wave exist because the rate of change (first derivative) of a square wave consists of very high, sudden peaks; infinitely high spikes, in the limit-case of a so-called perfect square wave. Real physical systems can’t follow such high rates, so the signals get distorted.