$\newcommand\tr{\operatorname{tr}}$Let $$Q(B):=(Y-XB)^T(Y-XB).$$ Since the column spaces of the matrices $X^TX$ and $X^T$ are the same, there is a matrix $B_*$ such that $$X^TXB_*=X^T Y.$$ For each $z\in\Bbb R^{p\times1}$, by (say) differentiating the convex function $B\mapsto z^T Q(B)z$ in $B$, we see that $B_*$ is a minimizer of this function. So, $B_*$ is a minimizer of $Q(B)$ in $B$ wrt to the [Loewner ordering][1]. So, $B_*$ is a minimizer of both $\tr Q(B)$ and $\det Q(B)$ in $B$. Generically, $\tr Q(B)$ is strictly convex in $B$, and then $B_*$ is a unique minimizer of $\tr Q(B)$. However, a minimizer of $\det Q(B)$ is not unique. For instance, suppose that $$X=\left( \begin{array}{cc} 1 & 3 \\ 1 & 1 \\ \end{array} \right), \quad Y=\left( \begin{array}{cc} 3 & 0 \\ 2 & 1 \\ \end{array} \right).$$ Then $$B_*=\frac12\,\left( \begin{array}{cc} 3 & 3 \\ 1 & -1 \\ \end{array} \right)$$ is the unique minimizer of $\tr Q(B)$. However, $$\left( \begin{array}{cc} 0 & 0 \\ 0 & -1 \\ \end{array} \right)$$ is a minimizer of $\det Q(B)$. [1]: https://en.wikipedia.org/wiki/Loewner_order