In thermodynamic systems why must the free energy of the system be minimized? Is this somehow a consequence of the second law of thermodynamics? 
 A: Let's say we have a system where the number of states at an energy $U$ is given by the function $N(U)$, so that the entropy $S(U)$ is given by $S(U)=\log N(U)$.
Now suppose this system is put in contact with a large thermal resevoir at temperature $T$. What energy will our system likely have after this contact has been made?
To answer this question we must ask how many states there are where our system has an energy $U$. We know the total number of states for our system is $e^S$, but what is the total number of states for the resevoir? The total number of states for the resevoir is similarly $e^{S_R(U_{\textrm{Total}} - U)}$, where $S_R(U_{\textrm{Total}}-U)$ is the entropy of the resevoir when it has energy $U_{\textrm{Total}}-U$ and $U_{\textrm{Total}}$ is the total energy of the bath plus resevoir system.
Since the state of the resevoir and the state of our system can be chosen independently, the total number of states for the combined system is the product of the number of states for the individual system. Thus the total number of states for the combined system is $e^S e^{S_R(U_{\textrm{Total}} - U)} =e^{S(U)+ S_R(U_{\textrm{Total}} - U)}$. If we expand the entropy of the resevoir we find 
\begin{equation}
\begin{aligned}
S_R(U_{\textrm{Total}} - U) &\approx S_R(U_{\textrm{Total}}) - U * \partial_U S \\
&= S_R(U_{\textrm{Total}}) -  U /T \\
\end{aligned}
\end{equation}
 so that the total number of states is proportional to $e^S e^{- U/T} =e^ {S- U/T} = e^{(TS-U)/T} = e^{-F/T} $. 
The system will almost certainly have the most probably energy. The most probably energy is the one that corresponds to the most states. Therefore it is the one that maximizes $e^{-F/T}$. Therefore it must be the one that minimizes $F$.
A: Strictly speaking a thermodynamic system is at equilibrium if and only if the free energy is at a local minimum in phase space. If the free energy was not at a minimum, the system would have a driving force that would pull it toward a local minimum. Think of a ball rolling down a hill. As the system falls toward the minimum, entropy is generated. So you can think of it as a consequence of the 2nd law, or vice-a-versa. 
It's worth noting that an equilibrium system is not necessarily at a global minimum. For example, a super heated liquid is in a shallow minimum of phase space. Add a little energy to it to bump it out of this minimum, and bang! Tons of energy is released (and entropy generated) as it falls to a much deeper minimum.
Also, technically, there is no way to know if a thermodynamic system is at a global minimum. You'd have to map out the entire phase space of the system, which is unknown.
