Let $(E,d)$ be a metric space, then $(x,y) \rightarrow d(x,y)$ is a continuous function from $E^2$ to $\mathbb{R},$ so $d$ is $(B(E^2),B(\mathbb{R}))$-measurable. Is it true that $d$ is $(B(E)\otimes B(E),B(\mathbb{R}))$-measurable ?
We know that $B(E)\otimes B(E) \subset B(E^2),$ and if $E$ is separable then we have equality. So is there an example where a distance function is not $(B(E)\otimes B(E),B(\mathbb{R}))$-measurable and the metric space is not separable ? Also we should mention, each time, that $(f,h)$ is $(B(E),B(E^2))$-measurable?
Because in the following lemmas, from Foundations of Modern Probability, they are taking measurable functions in a metric space, $f, h,$ for example, and taking $d(f,h)$ as a measurable function, without checking it is measurable or not.
On the other hand, in Real Analysis and Probability, they mentioned that $E$ must be separable.


At issue is whether $\mathscr{B}(E)\otimes\mathscr{B}(E)=\mathscr{B}(E^2)$. Separability is sufficient for equality.
Theorem: Let $(X,\tau_X)$ and $(Y,\tau_Y)$ be two topological spaces and let $\tau_{X\times Y}$ be the product topology on $X\times Y$. If $\mathscr{B}_X$, $\mathscr{B}_Y$ and $\mathscr{B}_{X\times Y}$ are the corresponding Borel $\sigma$--algebras, then $\mathscr{B}_X\otimes\mathscr{B}_Y\subset\mathscr{B}_{X\times Y}$. Equality holds if both $X$ and $Y$ are second countable.
Here is a short proof:
As the map $p_X:(x,y)\mapsto x$ is continuous on $(X\times Y,\tau_{X\times Y})$, $\{A\times Y: A\in\mathscr{B}_X\}\subset \mathscr{B}_{X\times Y}$. Similarly, using $p_Y:(x,y)\mapsto y$ instead, we obtain that $\{X\times B: B\in\mathscr{B}_Y\}\subset\mathscr{B}_{X\times Y}$. Therefore, $\mathscr{B}_X\otimes\mathscr{B}_Y\subset\mathscr{B}_{X\times Y}$.
If $\tau_X$ and $\tau_Y$ have countable bases $\mathcal{B}_X$ and $\mathcal{B}_Y$ respectively, then $\mathcal{T}=\{U\times V: U\in \mathcal{B}_X,\, V\in\mathcal{B}_Y\}$ is a countable base for $\tau_{X\times Y}$. It follows that $\tau_{X\times Y}\subset \sigma(\mathcal{T})= \mathscr{B}_X\otimes\mathscr{B}_Y$.
To give some perspective in the case of the OP I will make use of the following result:
For any set $A\subset X\times Y$, let $A_x=\{y\in Y:(x,y)\in A\}$, and $A^y=\{x\in X: (x,y)\in A\}$.
Lemma: Let $(X\times Y,\mathcal{A}\otimes\mathcal{B})$ be the product space of the measurable spaces $(X,\mathcal{A})$ and $(Y,\mathcal{B})$. For any $C\in\mathcal{A}\otimes\mathcal{B}$, the collection of sections $\{C_x:x\in X\}$ has at most the cardinality of the continuum. In particular, if $\Delta=\{(x,x): x\in X\}\in \mathcal{A}\otimes\mathcal{A}$, then $X$ has at most the cardinality of the continuum.
Here is a short proof:
There exists a sequence $\mathscr{S}=\{A_n\times B_n: A_n\in\mathcal{A},\,B_n\in\mathcal{B}\}$ such that $C\in\sigma(\mathscr{S})$. Let $F:X\rightarrow\{0,1\}^\mathbb{N}$ and $G:X\rightarrow\mathcal{P}(X)$ be the maps given by $x\mapsto(\mathbb{1}_{A_n}(x):n\in\mathbb{N})$, and $x\mapsto C_x$ respectively. If $F(x_1)=F(x_2)$, then the collection $\mathcal{D}\subset X\times X$ for which $D_{x_1}=D_{x_2}$ is a $\sigma$--algebra that contains $\mathscr{S}$ and so, $C_{x_1}=C_{x_2}$. Thus, there is a unique surjective function $h:F(X)\rightarrow G(X)$ such that $G=h\circ F$. For each $C_x$, choose $\boldsymbol{a}\in h^{-1}(C_x)$ (here we use the Axiom of choice). This defines a one--to--one map from $\{C_x:x\in X\}$ and a subset of $\{0,1\}^\mathbb{N}$. Hence $\{C_x:x\in X\}$ has at most the cardinality of the continuum.
The last statement follows from the fact that $\Delta_x=\{x\}$ for each $x\in X$.
Example: If $(S,\rho)$ is a metric space whose cardinality is larger than that of the continuum (thus, it can't be separable), then $\mathscr{B}(S)\otimes\mathscr{B}(S)\neq \mathscr{B}(S\times S)$. The diagonal $\Delta$ is a closed subset of $S\times S$ and so, $\Delta\in\mathscr{B}(S\times S)$; however, $\Delta\notin\mathscr{B}(S)\otimes\mathscr{B}(S)$.
As for measurability of functions that take values on a general metric space we have the following result:
Theorem: Suppose $(\Omega,\mathscr{F},\mu)$ is a measure space, and $(S,\rho)$ is a metric space. If $f:\Omega\rightarrow S$ is Borel measurable and $f(\Omega)$ is separable, then $f\in\mathscr{M}_S(\mu^*)$ ($\mu^*$ is the minimal extension of $\mu$ to a complete measure on a $\sigma$--algebra $\mathscr{M}_S(\mu^*)$ that contains $\mathscr{F}$ as in Carathéodory's extension theorem).
The proof requires a slightly more general notion of measurability and one approach uses uniformities. I will skip the details that although not difficult, are rather technical.