Basis-independent definition of linear Lie algebras 1. Definition via matrices
One way to define the linear Lie algebras $\mathfrak{so}(m, K)$ and $\mathfrak{sp}(m, K)$ is as the set $\{M \in \mathfrak{gl}(m,K) | SM=-M^TS\}$ where $S$ is a matrix that depends on whether you consider $\mathfrak{so}(m, K)$ or $\mathfrak{sp}(m, K)$.
For instance, for $\mathfrak{so}(2n, K)$ let $S$ be $\begin{bmatrix}
0 & I_n\\
I_n & 0\\
\end{bmatrix}$.
For $\mathfrak{so}(2n+1, K)$ let $S$ be $\begin{bmatrix}
1 & 0 & 0\\
0 & 0 & I_n\\
0 & I_n & 0\\
\end{bmatrix}$.
For $\mathfrak{sp}(2n, K)$ let $S$ be $\begin{bmatrix}
0 & I_n\\
-I_n & 0\\
\end{bmatrix}$.
2. Basis-independent definition
There is a basis-independent description. Apparently, in this definition the counterpart of the matrix $S$ becomes a non-degenerate bilinear form $b(-,-): V \times V \rightarrow K$ which is symmetric for $\mathfrak{so}(m, K)$ and skew-symmetric for $\mathfrak{sp}(m, K)$. Supposedly, the Lie subalgebras defined above then consist of exactly those endomorphisms $f: V \rightarrow V$, such that $b(f(v),w)=-b(v,f(w))$ for all $v,w \in V$.
My questions are these: What is the precise relationship between the matrices $S$ and the non-degenerate bilinear form $b(-,-)$? Is $S$ the matrix representation of the bilinear form with respect to a certain basis? Why require that the bilinear form be non-degenerate?
 A: As Travis Willse writes in a comment, let $V$ be a finite-dimensional $K$-vector space and $b: V \times V \rightarrow K$ a non-degenerate bilinear form, either symmetric or skew-symmetric (and for safety, let's assume $char(K)=0$). Choose a basis $e_1, ..., e_m$ of $V$ and let $S$ be the matrix with entries $S_{ij} :=b(e_i, e_j)$. Note that $S$ is (skew-)symmetric iff $b$ is.
Note that if $v = \sum v_i e_i, w = \sum w_i e_i$ then $b(v,w) = \pmatrix{v_1 \cdots v_m} \cdot S \cdot \pmatrix{w_1 \\ \vdots \\ w_m}$ (where $\cdot$ denotes ordinary matrix multiplication), which, with a little abuse of notation, we can write as $$b(v,w) = v^T S w.$$
Further, everyone learned in their first Linear Algebra course how our choice of basis induces an isomorphism
$$End_K(V) \simeq M_m(K) \\
f \mapsto M.$$
Now if $f \in End_K(V)$ satisfies $b(f(v), w) = - b(v, f(w))$ for all $v,w$, then equivalently, for the matrix $M$ corresponding to $f$,
$$(Mv)^T S w = -v^TS (Mw) \\
v^TM^T S w = -v^T S M w$$
for all $v,w \in V$ which by the non-degeneracy of the form implies (and is implied by)
$$M^T S = -SM$$
and of course it doesn't matter on what side you put the minus.

Note that the same bilinear form $b$ can give out two different matrices $S_1,S_2$ here if we choose different bases. In that case, $S_1$ and $S_2$ will be congruent i.e. there will exist an invertible matrix $P$ such that $S_2 = P^TS_1 P$. The matrix Lie algebras then look different, but of course conjugation with that same base change matrix $P$ (now using the inverse instead of the transpose) will show those seemingly different matrix Lie algebras are isomorphic.
Actually, one can also scale the bilinear form / the matrix S with any non-zero scalar and get the same matrix Lie algebra.
In general, these two are the only things we can do to keep the Lie algebras isomorphic.
As Travis also points out, the matrices which you write down as $S$ there over a general field give the so-called split forms of these Lie algebras. Over algebraically closed fields, there are no others anyway, as for example any $2n \times 2n$-symmetric matrix over $\mathbb C$ is congruent to a scaled version of your $S$.
That is not true over other fields though! E.g. over the real numbers, remember that Sylvester's Inertia Theorem gives us several different non-congruent symmetric bilinear forms. Your $S$ for $m=2n$ and the orthogonal group is congruent to a matrix of index $n$, i.e. to one with $n$ $1$'s and $n$ $-1$'s on the diagonal. This cannot be brought via congruence and/or scaling to the matrix $S'= I_{2n}$. Instead, this $S'$ gives a genuinely different Lie algebra, namely the classical "compact" one usually called $\mathfrak{so}_2n$, belonging to $b$ being the standard scalar product; when written out as matrices, this is just the Lie algebra of skew-symmetric real matrices. (And I stress again: Over $\mathbb R$, that is not isomorphic to the one you get with your $S$.)
Further reading:
What is this Lie group and does it have interesting properties?
What is the set of all matrices satisfying $\mathfrak{so}(n)$ definition?
Root space decomposition of $C_n=\mathfrak{sp}(2n,F)$ and further links in there.
