This work aims to study the effects of the variable stiffness of a compliant foot on humanoid locomotion performance. Through dynamical simulations, we demonstrate that the introduction of the variable stiffness feet, changing in conjunction with the ground roughness significantly improves the walking performance on different types of rough terrain of a humanoid robot. We propose a compliant foot model with multiple viscoelastic elements in the sole. We optimize the sole stiffness for different types of uneven terrains: with rocks, tiles, and obstacles of different shapes and dimensions. We implement a variable stiffness method according to the ground roughness during the walking. Furthermore, the timing of ground scanning and optimal stiffness estimation throw the k-nearest neighbors (KNN) algorithm is described. The comparison of the results obtained with completely flat sole, compliant sole with fixed stiffness, and compliant sole with variable stiffness show the superiority of the variable stiffness feet over the two others. Finally, we present some limitations of the flexible robotic foot in the dynamic simulation.