A unified theory of emergent equilibrium phenomena in active and passive matter