Setup: Spring (force constant k) + gas in heat bath. Piston at displacement x from equilibrium; gas volume V=V1+Ax where A is piston area.

Equilibrium condition: ∂F∂x=0

∂F∂x=∂E∂x−T∂S∂x

Energy term — gas is at constant T, so its energy doesn't change with x. Only the spring contributes:

∂E∂x=Fpiston=−kx

Entropy term — piston has no entropy; only the gas contributes:

∂S∂x=∂S∂V∂V∂x=PT⋅A=FgasT

Substituting:

∂F∂x=Fpiston−Fgas=0⟹Fpiston=Fgas

Result: Minimising free energy is equivalent to balancing forces.