I know that for a pendulum we need small amplitudes. But why is it necessary that a spring oscillator should have small amplitude of oscillation?
Small amplitudes are only required for the pendulum.
However, it's true that we could expand it to all SHM. Why? Because a simple harmonic motion (SHM) is the motion caused by an ideal spring.
That is, a motion caused by a force $F=-k\cdot x$
The thing is that this is an idealization. As always, reality isn't that beautiful. There is friction, and there are many other effects. In particular, if you pull a spring too much, you might deformate it. Then, it won't obey $F=-k x$ any longer.
In conclusion: if amplitudes are too big, a REAL spring might cease to fulfill $F=-kx$, so it won't cause SHM any longer.
But that's for REAL spring. On paper, we always treat them as ideal springs, which satisfyf $F=-kx$ for ANY ampltiude. This is how we model reality. Reality is always more complex.
The equation of motion of the simple pendulum is:
This solves for small $\theta$ because then:
$$\sin \theta \approx \theta$$
For the mass-spring SHO the EoM is:
As long as $k$ remains invariant of $x$, no approximation is needed. Amplitude now doesn't matter (within reason).