The other answers are good, but one other way to view this is as a difference between the set-theoretic and type-theoretic views of functions.
In set theory, a function $f$ is defined by the relation $f = \{(x, f(x)) : x \in \text{dom}(f)\}$ of pairs from the domain and codomain. To be a function, a relation $r$ must simply not have $y_1 \neq y_2$ for a given $x$ such that $(x, y_1) \in r$ and $(x, y_2) \in r$. In this view, we have $\text{dom}(f) = \{x : (x, y) \in f\}$ and $\text{range}(f) = \{y : (x, y) \in f\}$. As other answers have mentioned, the codomain doesn't really matter. If two functions represent the same set of pairs when considered as relations, they are equal.
But in type theory, we must first define the type of a function by writing something like $f : A \to B$, so informally $\text{dom}(f) = A$ and $\text{codom}(f) = B$. In this view, we can't even meaningfully ask the question of whether $f$ is equal to another function $g : A \to B'$ unless $B$ and $B'$ are the same, because otherwise $f$ and $g$ would not be the same type. It would be like asking whether the color blue is equal to the number $3$. They're different types, and equality is only well-defined for two objects of the same type.
The reason your two books seem to give different answers to these questions is that mathematicians typically don't strictly use either set theory or type theory, and instead intuitively use an amalgamation of both. This question of whether the codomain matters for function equality only really becomes more important when you start delving deeper into set theory and/or type theory per se.