I want to prove matrix $C$ is invertible: $$C=I-A^TB(B^TB)^{-1}B^TA(A^TA)^{-1},$$ where $I$ is an identity matrix of appropriate dimensions, and $(A^TA)^{-1}$ and $(B^TB)^{-1}$ imply both $A$ and $B$ have linearly independent columns.
I tried to achieve my goal by proving $\det(C)\neq0$ but got stuck.
Given $\mathrm A \in \mathbb R^{m \times n}$ and $\mathrm B \in \mathbb R^{m \times p}$, both having full column rank, we define $\mathrm C \in \mathbb R^{n \times n}$ as follows
$$\mathrm C := \mathrm I_n - \mathrm A^T \mathrm B (\mathrm B^T \mathrm B)^{-1} \mathrm B^T \mathrm A (\mathrm A^T \mathrm A)^{-1}$$
Using the Weinstein-Aronszajn determinant identity,
$$\begin{array}{rl} \det (\mathrm C) &= \det (\mathrm I_n - \mathrm A^T \mathrm B (\mathrm B^T \mathrm B)^{-1} \mathrm B^T \mathrm A (\mathrm A^T \mathrm A)^{-1})\\\\ &= \det (\mathrm I_m - \mathrm A (\mathrm A^T \mathrm A)^{-1} \mathrm A^T \mathrm B (\mathrm B^T \mathrm B)^{-1} \mathrm B^T)\end{array}$$
Note that
$$\mathrm P_{\mathrm A} := \mathrm A (\mathrm A^T \mathrm A)^{-1} \mathrm A^T \qquad \qquad \qquad \mathrm P_{\mathrm B} := \mathrm B (\mathrm B^T \mathrm B)^{-1} \mathrm B^T$$
are the $m \times m$ projection matrices that project onto the column spaces of $\mathrm A$ and $\mathrm B$, respectively.
Hence,
$$\det (\mathrm C) = \det (\mathrm I_m - \mathrm P_{\mathrm A} \mathrm P_{\mathrm B})$$
and, thus, if $\mathrm I_m - \mathrm P_{\mathrm A} \mathrm P_{\mathrm B}$ is invertible, so is $\mathrm C$.