Conditions for using the work-energy theorem Suppose I let a block fall from a height above a vertical spring. Any air drag is ignored. I want to find the maximum compression the spring will undergo. Is it possible to use the work-energy theorem over the Course of the entire motion?
The confusion is due to the fact that the spring force doesn't act throughout the entire motion, so isn’t part of the “net” force through a specific part of the time interval. Since the work energy theorem is derived by newton’s second law, is the theorem still applicable? I guess could consider the spring force as a discontinuous function that is 0 for all positive extensions but this feels wrong.
I know I can solve this easily using conservation of mechanical energy but I just want to know if the work energy theorem csn be applied to situations like these.
 A: 
I want to find the maximum compression the spring will undergo. Is it
possible to use the work-energy theorem over the Course of the entire
motion?

Yes it is. But you will have to apply it in two parts.
The work energy theorem states that the net work done on an object equals its change in kinetic energy.
During the fall up to the point where the object contacts the spring the only force acting on the object is gravity. So if the object starts at rest you can determine its change kinetic energy at the point of impact based on the work done by gravity. The change in kinetic energy will be $mgh$ where $h$ is the distance the object falls before impacting the spring.
After that you can reapply the work energy theorem after impact. The net work done on the object will then be equal to the integral of the net force applied, $kx-mg$, times the spring displacement, $dx$, and set that equal to the loss in kinetic energy, $mgh$, or
$$\int (kx-mg)dx=mgh$$
$$\frac{kx^2}{2}=mgx+mgh$$
But you can also use conservation of energy where the energy stored in the spring upon stopping the object is $\frac{kx^2}{2}$, where $x$ is the compression of the spring, equals the loss of the kinetic energy, $mgh$, plus the loss of additional gravitational potential energy during compression of the spring, $mgx$, or
$$\frac{kx^2}{2}=mgh+mgx$$

Thanks, i think i get it now. So at the end, I would have just arrived
at the same result as if I had just taken thr work done by gravity
mg(x+h)? Is this always the case? –

It is only correct if the overall change in kinetic energy is zero, which in this case it is. The object starts at rest and comes to a rest when the spring is fully compressed. Therefore, the overall change in kinetic energy is zero. Per the work energy theorem, that means the net work done on the object is zero. In this case gravity does positive work equal to $mg(x+h)$. The spring does negative work of $-\frac{kx^2}{2}$ because the direction of its force is opposite the direction of displacement. Therefore, the net work is
$$W_{net}=mg(h+x)-\frac{kx^2}{2}=0$$
$$\frac{kx^2}{2}=mg(h+x)$$.
Or, to put it another way, the loss of gravitational potential energy equals the gain in spring potential energy.
Hope this helps.
A: You can apply work energy theorem.
Work energy theorem states that Work done by all forces = $\Delta KE$
Edit : My earlier answer was wrong.  I am trying to treat spring-block as a system .
I am assuming change in potential energy from the equilibrium  of the spring.
So if the distance of the block from the end of the spring is h , The system had a total potential energy of mgh.
Now when it falls to the falls through height h it gain some kinetic energy.
where $v=\sqrt{2gh}$.  Hence KE of the system : $1/2mv^2 = {mgh}$
Now when the the spring block will have an equilibrium position where Spring Force equals to gravitational force.Let's call that compression of the spring d
$K(d)=mg$ , $\therefore d = mg/K $
Now Total change in energy i.e  total change in Kinetic energy of the block is divided is shared between spring potential energy and it's own gravitational potential energy, $mg(h+d)-1/2Kd^2$
But since this was our reference line , the line from where we were measuring all the distances all the potential energy = 0 here.
From this point we will deal the spring block as a system .We don't treat block and spring as two different objects i.e after that change in gravitational energy of block =0 , The only change we will observe is change is change in spring potential energy.
If A is the maximum amplitude of the spring-block system then :
$\therefore$ $$mg(h+d)-1/2Kd^2=1/2KA^2$$
Now substitute $d=mg/K$
We get $$A=\frac{mg}{k}\sqrt {1+2hK/mg}$$
A: 
Find the maximum compression in the spring when a mass $m$ is dropped on it from height $H$ above it.

Measuring $x$ as positive upwards from the point of maximum compression,
\begin{align*}
-mg+F_S&=m\frac{d^2x}{dt^2}\\
-mg+F_S&=mv\frac{dv}{dx}\\
-mg+F_S&=\frac m2\frac{dv^2}{dx}\\
-mg+F_S&=\frac{d}{dx}\left(\frac12 mv^2\right)&(\because m=\text{constant})\tag{1}\\
\int_{H+x_0}^{0}(-mg+F_S)dx&=\int_0^0 d\left(\frac12 mv^2\right)\\
\int_{H+x_0}^{H}(-mg+\color{red}{0})dx+\int_{H}^{0}(-mg+kx)dx&=0\\
-mg[x]_{H+x_0}^{H}-mg[x]_{H}^{0}+\frac12k[x^2]_{H}^{0}&=0\\
\frac k2x_0^2-mgx_0-mgH&=0\\
\boxed{x_0=\frac{mg}k\sqrt{1+2\frac{kH}{mg}}}\\
\end{align*}
It doesn't matter if spring force is $\color{red}{0}$ for the time the mass travels its height above the spring, the equation $(1)$ will always be valid for all the values $x$ can take i.e. throughout the motion. The values of any contributing force automatically partakes as $\color{red}{0}$ in the equation if it is $\color{red}{0}$ for some time.

The takeaway is to go to the very proof of the theorem when you fear its consistency to be at stake.
