In this answer I will argue that for the thermodynamic free energy expressions there is no variational path that leads to them.
I will first discuss optimization in general. Then I will discuss that variational treatment is applicable only for a particular subset of the set of all optimization problems. The criterion that defines that subset is relevant for discussion of why it is possible to use calculus of variations in dynamics.
Among the best known optimization problems is the traveling salesman problem. The traveling salesman problem has a feature that is shared by most optimization problems, but not all. Let's say you have a map with 10 cities. Divide the map in two submaps, so that you have two groups of 5 cities. Obviously, if you take the solution for each the two sub-solutions, and you concatenate those two itenaries, then that concatenated itenary is very unlikely to be optimal for the set of 10 cities as a whole. I will refer to that property of the problem as: non-concatenable.
For contrast: an optimization problem that does have the property of being concatenable: the catenary problem
The catenary problem
The catenary problem has the following property: if you subdivide the span in subsections, and you solve for the optimum of each subsection, then the concatenation of all of those subsections is the solution of the original problem.
There is no lower limit to how far you can subdivide. You can subdivide all the way down to infinitesimally short subsections.
Calculus of Variation capitalizes on that property. As we know: the Euler-Lagrange equation is a differential equation. It is possible to restate the problem in differential form because the crucial property obtains at the scale of infinitesimally short subsections, and from there it propagates out to the curve as a whole
As we know: the solution to a differential equation is a function. The solution to a differential equation is a function that satisfies the differential relation over the entire domain concurrently.
When we set out to solve the catenary problem we want to find a curve such that the potential energy is minimal.
Instead of finding that minimal directly, it is found indirectly. The minimal curve has the property that if you change it anywhere, either up or down, the potential energy is raised.
So you take the derivative of the potential energy with respect to variation.
The variation is variation of height. So in the case of the catenary problem the derivative that is being evaluated is derivative with respect to the height coordinate.
What you are looking for is a curve such that the derivative of the potential energy with respect to the height coordinate is zero for every infinitesimally small subsection along the curve.
As we know: potential energy is defined as the negative of work done, and work done is the integral of force with respect to position coordinate.
That means:
When you take the derivative of the potential energy with respect to height you recover the force.
(The above discussion is a highly abbreviated version of material that is on my own website. Link to my website is on my stackexchange profile page.)
Calculus of Variations in Dynamics
That calculus of variations is applicable to solve static optimization problems such as the catenary problem is totally expected, of course.
The fact that Calculus of variations can be used in dynamics is surprising. Our sense of surprise is justified: while it can be used, there is a caveat. To illustrate that caveat: Fermat's stationary time.
Fermat's Principle
The content of Fermat's principle is: the actual path of the light has the property that the derivative with respect to variation of the total time is zero.
The Fermat time is not in all cases least time. To show that:
Take the case of the inside of an ellipse as reflecting surface, with point of emission at one focus of the ellipse, and point of absorption at the other focus. As we know: then for every direction of emission the travel time is the same; that's a geometric property of the ellipse.
Now keep the position of the emission and absorption point, and make the minor axis of the ellipse smaller. With the reflecting surface less concave there is a single (reflection) point of least travel time
Conversely, keep the position of the emission and absorption point of the original ellips, and make the minor axis larger. That makes the reflection surface more concave and with that setup the true path of reflection of light is among all paths the one with maximum time.
This is a key point: depending on the circumstances the true path of the light can correspond to a minimum of the Fermat time, or a maximum of the Fermat time. The actual criterion is the one that the two have in common: that the derivative of the Fermat time with respect to variation is zero.
(A full discussion, illustrated with interactive diagrams, is available on my website)
Hamilton's stationary action has the same property: within the scope of Hamilton's action there are also classes of cases such that the true trajectory corresponds to a maximum of Hamilton's action.
For that reason, and other reasons: there is no room for an interpretation in terms of some form of optimization. The notion that some form of optimization is involved must be abandoned.
(Any attempt to rescue the optimization interpretation is comparable to adding more epi-cycles )
when calculus of variation is applied in dynamics then the crucial step is the act of taking the derivative with respect to the position coordinate: that is the operation that makes it work for dynamics.
With all of the above in place:
whether for the thermodynamic free energy espressions there is a variational path that leads to them.
We have that Hamilton's stationary action does not involve any notion or form of optimization.
But: as you describe in your question: what you need is a process that embodies a form of optimization. So that is already a mismatch.
Assertion:
The only way to get the results that are achievable with statistical mechanics is to apply statistical mechanics.
In Oct. 2021 I posted a discussion of Hamilton's stationary action, in an answer to a question titled Example in motivation for Lagrangian formalism
As stated earlier: link to discussion - on my own website - of application of calculus of variation is available on my stackexchange profile page.