Second-harmonic scattering (SHS) experiments provide a unique approach to probe noncentrosymmetric environments in aqueous media, from bulk solutions to interfaces, living cells, and tissue. A central assumption made in analyzing SHS experiments is that each molecule scatters light according to a constant molecular hyperpolarizability tensor β(2). Here, we investigate the dependence of the molecular hyperpolarizability of water on its environment and internal geometric distortions, in order to test the hypothesis of constant β(2). We use quantum chemistry calculations of the hyperpolarizability of a molecule embedded in point-charge environments obtained from simulations of bulk water. We demonstrate that both the heterogeneity of the solvent configurations and the quantum mechanical fluctuations of the molecular geometry introduce large variations in the nonlinear optical response of water. This finding has the potential to change the way SHS experiments are interpreted: In particular, isotopic differences between H2O and D2O could explain recent SHS observations. Finally, we show that a machine-learning framework can predict accurately the fluctuations of the molecular hyperpolarizability. This model accounts for the microscopic inhomogeneity of the solvent and represents a step towards quantitative modeling of SHS experiments.