On the measure-theoretic foundations of the second law of thermodynamics