The Pythagoras number of a field is the smallest natural number n such that every sum of squares in the field is a sum of n squares. Given a nondyadic henselian valued field (K,v), we show that the best bound on the Pythagoras number for function fields of curves over K is essentially the same as for function fields of curves over the residue field Kv. As a consequence, we obtain the upper bound 5 for the Pythagoras number of function fields of curves over any field K for which the rational function field K(X) has Pythagoras number 2. The proof uses a reduction to the case where the value group is a subgroup of the real numbers, where then a local-global principle for quadratic forms due to V.~Mehmeti is applied.