Here is the solution of the question (which asks us to prove that the relation of homotopy among maps $X \rightarrow Y$ is an equivalence relation):
My question is about the last part of proving transitivity. Why while applying the Pasting lemma the author of the solution was sure that $X \times [0,1/2]$ and $X \times [1/2, 1]$ are closed even though we do not have any information about the closure of $X.$ Could anyone explain this point for me please?

The total space we're working in, is $X \times I$ and $X \times [0,\frac12]$ is closed in it, because it's $\pi_2^{-1}[[0,\frac12]]$, the inverse image of the projection under a closed set. And by definition of the product topology these are closed in $X \times I$.
$X$ is closed in itself (as in any topology), but that's irrelevant.
Wherever $X$ "came from" (a subspace of some earlier space maybe), we're treating it as a space in its own right and put the product topology on $X \times I$.