This answer assumes you understand the defining property of homothetic functions, namely, slope of their level curves being equal for a given input ratio. First let's understand what is the diagonal; it is a line representing endowment ratio $X_1:X_2$ in the economy. Contract curve being linear is equivalent to it lying on the diagonal, since contract curves must begin and end at the origins.
Why do you say that the given pair of utility functions have linear contract curve? You did not mention any specific endowment ratio, so I am assuming you are asking for when a pair of utility functions have linear contract curve for any endowment ratio. The equation of contract curve with endowment ratio $X_1:X_2$, and differentiable utility functions $A,B$ is:
$$
\mathrm{MRS}_A = \mathrm{MRS}_B \tag1 $$ For your example,
$$\frac{0.5 x_1^{-0.5} x_2{}^{0.5}}{0.5 x_1{}^{0.5} x_2^{-0.5}}
= \frac{(X_2-x_2)^{0.5}}{0.5 (X_1 - x_1) (X_2 - x_2)^{-0.5}} \tag 2
$$
Plot the above in a graphing calculator like Desmos, and you can see that the contract curve is not linear for any endowment ratio. For rigour, you can solve for $x_1$ in terms of $x_2$ to see if the function is linear, but I suppose this would not be possible to do if the contract curve was quintic or higher (lack of closed formed solution of quintic).
The contract curve of any homothetic utility function will lie on one side of the diagonal or entirely on the diagonal; it will lie entirely on the diagonal if there exists at least one optimum point on the diagonal. See In a box diagram, why does efficiency locus lie on one side of the diagonal, if both sectors haves constant returns to scale function?. LHS of (1) is a constant for a given $X_1 : X_2$, so is the RHS, if both functions are homothetic. (1) will hold if these constants are equal. These constants are equal when for a given price, both consumers consume the same commodity ratio. If $A$ consumes $2x_1$ of $x_2$, so will $B$ i.e., relative preference of one commodity is same for both consumers. Constants being equal, and consequently, (1) holding for $X_1:X_2$ necessarily means that contract curve lies on the diagonal. This is the sufficient condition for linear contract curve, and any function satisfying this condition, will have linear contract curve for any endowment ratio, because we did not assume any specific ratio (see below, where we do assume).
Though this is not a necessary condition. Giskard's answer shows a non-differentiable function, namely $\min(x,y)$ (this is a Leontief utility function) where contract curve is linear. But this specific function will have linear contract curve only if the endowment ratio is 1:1; (4:4) in Giskard's case. This is because the kink (which is the optimum point for Leontief utility functions) is at $x_1=x_2$. If they used a function such as $\min(2x_1,x_2)$, the endowment ratio would need to be $1:2$.
(EDIT)
In (2) I had misunderstood utility function of $A$ being $\sqrt{x_1x_2}$ and that of $B$ as $x_1\sqrt{x_2}$. It seems you were providing 2 examples of both consumers having the same utility function, while I understood it as 1 example of 2 consumers having different utility functions. If you substitute the same utility function, then yes, the contract curves are linear in your example. I am still leaving this answer up, because it gives the sufficient condition of consumers having different utility, which is just a more general answer.