We prove that if a geodesic metric measure space satisfies a comparison condition for isoperimetric profile and if the observable variance is maximal, then the space is foliated by minimal geodesics, where the observable variance is defined to be the supremum of the variance of 1-Lipschitz functions on the space. Our result can be considered as a variant of Cheeger-Gromoll's splitting theorem and also of Cheng's maximal diameter theorem. As an application, we obtain a new isometric splitting theorem for a complete weighted Riemannian manifold with a positive Bakry-Emery Ricci curvature.