I came across an issue which bugs me.
Considering an ideal gas of $N$ non-interacting particles on a $1D$ container of length $L$, its (configurational) entropy $S$ reads $$ S = kT \ln \Big(\frac{L^N}{N!} \Big) = kT N \Big( \ln (\frac{L}{N})+1 \Big)$$ the last step being justified by Stirling's approximation for large $N$. The configurational entropy is all there is in this system, no energy contribution for the free energy.
The particles are non-interacting so one would assume that the entropy would grow as the number of particles increases.
Yet that is not the case: $S$ is not monotonic, and $$ \frac{\partial S}{\partial N} = -kT \ln \Big( \frac{L}{N}\Big) $$ equals $0$ for $N = L$, whatever (positive) $T$.
So if one puts the box of side $L$ in contact with a particle reservoir, from which partciles can come and go without penalties, $N$ particles are required to minimise the free energy.
This is most surprising, and it comes from having included the $N!$ term in the denominator of the entropy expression. A rather significant change: without $N!$ term the entropy grows monotonically with $N$.
But how come? Where does this limit on the number of particles comes from, if they are non-interacting? I would expect, the more of them, the higher the entropy.
EDIT
following requests for clarification, I add details on howthe formula in question is derived. The partition function $Z_1$for an "energyless" particle (no interactions, no kinetic energy) in a 1D box of length $L$ is given by $$ Z_1 = \int_0^L \exp{-(\frac{0}{kT}}) \mathrm{d}x = L$$ As we have $N$ independent indistinguishable particles, the overall partition function $Z$ equals $$ Z = \frac{Z_1^N}{N!}$$ As there is no energy, the free energy equals $-TS$, and the relationship betwwem $Z$ and free is the final step.