Non-local thermodynamic equilibrium effects determine the upper atmospheric temperature structure of the ultra-hot Jupiter KELT-9b