Let $V$ be a finite dimension vector space over the field $\mathbb{K}$, let $\langle \cdot , \cdot \rangle$ be a symmetric non-degenerate bilinear form on $V$, and let $f \colon V \to V$ be an endomorphism of $V$. It is well known that there exists the adjoint operator $f^*$ of $f$, i.e. $f^*$ is the unique endomorphism of $V$ such that $\langle v, f(w) \rangle = \langle f^*(v), w \rangle$ for all $v, w \in V$.
Now fix a basis $\mathcal{B} = \{v_1, \dots, v_n \}$ of $V$. Let $A,B, C \in M_{n,n}(\mathbb{K})$ be the matrices that represent $f$, $\langle \cdot , \cdot \rangle$ and $f^*$, respectively, respect to the basis $\mathcal{B}$ (I mean that $f(v_j) = \sum_i a_{ij} v_i$, $\langle v_i , v_j \rangle = b_{ij}$, and $f^*(v_j) = \sum_i c_{ij} v_j$.). One has $\langle v_i, f(v_j) \rangle = \langle v_i, \sum_k a_{kj} v_k \rangle = \sum_k a_{kj} b_{ik}$ and $\langle f^*(v_i), v_j \rangle = \langle \sum_h c_{hi} v_h, v_j \rangle = \sum_h c_{hi} b_{hj}$. From the equality that defines $f^*$, we have that $BA = \ ^t C B$, i.e. $C = B^{-1} \ ^t A B$, since $B$ is symmetric. (If $M$ is a matrix, the symbol $^t M$ denotes its transpose.)
A similar reasoning works in the hermitean case.