This study shows that the generalized Boltzmann distribution is the only distribution mathematically consistent with thermodynamics when the system is described by an ensemble of a certain mathematical form. This mathematical form is very general, such that the canonical, grand-canonical, or isothermal-isobaric ensemble theories are all special cases of this form. Compared with the standard textbook formalism of the statistical mechanics (SM), this approach does not require a prior distribution, does not assume the functional form or maximization of entropy, and employs fewer assumptions. Therefore, this new insight challenges the belief on the requirement of a prior distribution in SM and provides a new way to derive the Boltzmann distribution. This study also reveals the logical and mathematical constraints of SM's fundamental components; therefore, it could potentially benefit researchers on non-Boltzmann-Gibbs SM and philosophers studying the foundations of SM.