Inorganic perovskite solar cells could benefit from surface passivation using 2D/3D perovskite heterostructures. However, conventional spacer cations fail to exchange with the tightly bonded Cs cation in the inorganic perovskite to form 2D layers atop; or, when they do enable formation of a 2D layer, they migrate under heat, degrading device performance. Here we investigate the mechanisms behind 2D/3D heterostructure formation and stabilization. We find that 2D/3D heterostructure formation is driven by interactions between ammonium groups and [PbI6]4− octahedra. We thus incorporate electron-withdrawing fluorine to enhance inorganic–organic cation interdiffusion and promote heterostructure formation. We note that stability relies on interactions between the entire spacer cations and [PbI6]4− octahedra. We therefore introduce anchoring groups that double cation desorption energies, preventing cation migration at elevated temperatures. CsPbI3/(perfluoro-1,4-phenylene)dimethanammonium lead iodide heterostructures enable an efficiency of 21.6% and a maximum power point operating stability at 85 °C of 950 h. We demonstrate 16-cm2 modules with an efficiency of 19.8%.