Using molecular simulations, we study the processes of capillary condensation and capillary evaporation in model mesopores. To determine the phase transition pathway, as well as the corresponding free energy profile, we carry out enhanced sampling molecular simulations using entropy as a reaction coordinate to map the onset of order during the condensation process and of disorder during the evaporation process. The structural analysis shows the role played by intermediate states, characterized by the onset of capillary liquid bridges and bubbles. We also analyze the dependence of the free energy barrier on the pore width. Furthermore, we propose a method to build a machine learning model for the prediction of the free energy surfaces underlying capillary phase transition processes in mesopores.