Forming semiconductor heterojunctions is a promising strategy to boost the efficiency of solar-driven photoelectrochemical (PEC) water splitting by accelerating the separation and transport of photogenerated charge carriers via an interfacial electric field. However, there is limited research considering the influence of electrolytes on the band alignment of the heterojunction under PEC conditions. In this work, we use a single crystal NiCo2O4/SrTiO3 (NCO/STO) heterojunction with atomic-precision controlled thickness as a model photoelectrode to study the band structure modulations upon getting in contact with the electrolyte and the correlation with the PEC activity. It is found that the band alignment can be tuned by the control of p-n heterojunction film thickness and regulated by the water redox potential (Eredox). When the Fermi level (EF) of the heterojunction is higher/lower than the Eredox, the band bending at the NCO/STO-electrolyte interface will increase/decrease after contacting with the electrolyte. However, when the band bending width of the NCO layer is thinner than its thickness, the electrolyte will not influence the band alignment at the NCO/STO interface. In addition, PEC characterization results show that the 1 nm NCO/STO heterojunction photoanode exhibits superior water-splitting performance, owing to the optimum band structure of the p-n heterojunction and the shorter charge transfer distance.