[proofplan]
We first record that the weight-$k$ slash operators form a right action of $SL_2(\mathbb{Z})$ on functions $\mathbb{H} \to \mathbb{C}$. We then prove directly, using the Euclidean algorithm on the first column, that $S$ and $T$ generate $SL_2(\mathbb{Z})$. Finally, invariance under $S$ and $T$ gives invariance under their inverses, and the right-action identity propagates the invariance through any word in the generators.
[/proofplan]
[step:Verify that the slash operators compose as a right action]
Let
\begin{align*}
\gamma =
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix},
\qquad
\delta =
\begin{pmatrix}
e & r \\
g & h
\end{pmatrix}
\end{align*}
be elements of $SL_2(\mathbb{Z})$. Define
\begin{align*}
\gamma z := \frac{az+b}{cz+d},
\qquad
\delta z := \frac{ez+r}{gz+h},
\qquad z \in \mathbb{H}.
\end{align*}
The standard fractional linear action of $SL_2(\mathbb{Z})$ preserves $\mathbb{H}$, so all displayed expressions are defined for $z \in \mathbb{H}$.
The product is
\begin{align*}
\gamma\delta =
\begin{pmatrix}
ae+bg & ar+bh \\
ce+dg & cr+dh
\end{pmatrix}.
\end{align*}
For $z \in \mathbb{H}$,
\begin{align*}
((f|_k\gamma)|_k\delta)(z)
&= (gz+h)^{-k}(f|_k\gamma)(\delta z) \\
&= (gz+h)^{-k}\left(c\frac{ez+r}{gz+h}+d\right)^{-k}
f\left(\gamma(\delta z)\right) \\
&= \bigl((ce+dg)z+(cr+dh)\bigr)^{-k}
f\left(\frac{(ae+bg)z+(ar+bh)}{(ce+dg)z+(cr+dh)}\right) \\
&= (f|_k(\gamma\delta))(z).
\end{align*}
Thus
\begin{align*}
(f|_k\gamma)|_k\delta = f|_k(\gamma\delta)
\end{align*}
for all $\gamma,\delta \in SL_2(\mathbb{Z})$.
[guided]
The first structural fact we need is that the slash operation is compatible with matrix multiplication. Let
\begin{align*}
\gamma =
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix},
\qquad
\delta =
\begin{pmatrix}
e & r \\
g & h
\end{pmatrix}
\end{align*}
be matrices in $SL_2(\mathbb{Z})$. We write their fractional linear actions as maps
\begin{align*}
\gamma: \mathbb{H} &\to \mathbb{H},
&
z &\mapsto \frac{az+b}{cz+d}, \\
\delta: \mathbb{H} &\to \mathbb{H},
&
z &\mapsto \frac{ez+r}{gz+h}.
\end{align*}
These maps are defined on $\mathbb{H}$ because matrices in $SL_2(\mathbb{R})$ act on the upper half-plane by fractional linear transformations.
Now compute the iterated slash operation. For $z \in \mathbb{H}$,
\begin{align*}
((f|_k\gamma)|_k\delta)(z)
&= (gz+h)^{-k}(f|_k\gamma)(\delta z) \\
&= (gz+h)^{-k}
\left(c\frac{ez+r}{gz+h}+d\right)^{-k}
f\left(\gamma(\delta z)\right).
\end{align*}
The automorphy factors multiply as
\begin{align*}
(gz+h)\left(c\frac{ez+r}{gz+h}+d\right)
&= c(ez+r)+d(gz+h) \\
&= (ce+dg)z+(cr+dh).
\end{align*}
Also,
\begin{align*}
\gamma(\delta z)
&=
\frac{a\frac{ez+r}{gz+h}+b}{c\frac{ez+r}{gz+h}+d} \\
&=
\frac{(ae+bg)z+(ar+bh)}{(ce+dg)z+(cr+dh)}.
\end{align*}
Since
\begin{align*}
\gamma\delta =
\begin{pmatrix}
ae+bg & ar+bh \\
ce+dg & cr+dh
\end{pmatrix},
\end{align*}
the last two displayed identities give
\begin{align*}
((f|_k\gamma)|_k\delta)(z) = (f|_k(\gamma\delta))(z).
\end{align*}
Because this holds for every $z \in \mathbb{H}$, we have
\begin{align*}
(f|_k\gamma)|_k\delta = f|_k(\gamma\delta).
\end{align*}
This is the right-action identity used below.
[/guided]
[/step]
[step:Generate every matrix in $SL_2(\mathbb{Z})$ from $S$ and $T$]
Let $G$ be the subgroup of $SL_2(\mathbb{Z})$ generated by $S$ and $T$. We prove that $G = SL_2(\mathbb{Z})$.
Let
\begin{align*}
\gamma =
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
\in SL_2(\mathbb{Z}).
\end{align*}
Since $\det \gamma = ad-bc = 1$, the integers $a$ and $c$ are coprime. We shall left-multiply $\gamma$ by elements of $G$ until the lower-left entry becomes $0$.
If $c=0$, then $ad=1$, so $a=d=\varepsilon$ for some $\varepsilon \in \{1,-1\}$, and
\begin{align*}
\gamma =
\begin{pmatrix}
\varepsilon & b \\
0 & \varepsilon
\end{pmatrix}
=
\varepsilon I\, T^{\varepsilon b}.
\end{align*}
Since $S^2=-I$, both $I$ and $-I$ belong to $G$, and therefore $\gamma \in G$.
Assume now that $c \neq 0$. If $|a| < |c|$, left-multiplication by $S$ replaces the first column $(a,c)^\top$ by $(-c,a)^\top$, so the absolute value of the lower entry becomes $|a|$. If $|a| \ge |c|$, choose $q \in \mathbb{Z}$ such that the integer $r:=a+qc$ satisfies $|r| < |c|$; this is the [division algorithm](/theorems/725) applied to $a$ by $c$. Left-multiplication by $T^q$ replaces the first column $(a,c)^\top$ by $(a+qc,c)^\top=(r,c)^\top$, and then left-multiplication by $S$ replaces it by $(-c,r)^\top$. In either case, the absolute value of the lower entry strictly decreases.
Repeating this finite descent in the nonnegative integer $|c|$, we obtain an element $A \in G$ such that
\begin{align*}
A\gamma =
\begin{pmatrix}
\varepsilon & m \\
0 & \varepsilon
\end{pmatrix}
\end{align*}
for some $\varepsilon \in \{1,-1\}$ and $m \in \mathbb{Z}$. By the already treated case, $A\gamma \in G$. Since $A \in G$ and $G$ is a subgroup, $\gamma=A^{-1}(A\gamma)\in G$. Hence $SL_2(\mathbb{Z}) \subseteq G$, and the reverse inclusion holds by definition of $G$. Therefore $SL_2(\mathbb{Z})=G$.
[guided]
We need the concrete group-theoretic input that $S$ and $T$ generate $SL_2(\mathbb{Z})$. Let $G$ denote the subgroup of $SL_2(\mathbb{Z})$ generated by $S$ and $T$. We prove $G=SL_2(\mathbb{Z})$ by reducing an arbitrary matrix using the Euclidean algorithm.
Take
\begin{align*}
\gamma =
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
\in SL_2(\mathbb{Z}).
\end{align*}
The determinant condition gives
\begin{align*}
ad-bc=1,
\end{align*}
so the first-column entries $a$ and $c$ have greatest common divisor $1$. We now act on the left by powers of $T$ and by $S$. Left multiplication changes rows, hence changes the first column as follows:
\begin{align*}
T^q
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
&=
\begin{pmatrix}
a+qc & b+qd \\
c & d
\end{pmatrix}, \\
S
\begin{pmatrix}
a & b \\
c & d
\end{pmatrix}
&=
\begin{pmatrix}
-c & -d \\
a & b
\end{pmatrix}.
\end{align*}
Thus $T^q$ replaces the first column $(a,c)^\top$ by $(a+qc,c)^\top$, while $S$ replaces it by $(-c,a)^\top$.
The goal is to make the lower-left entry equal to $0$. If $c=0$, then $ad=1$, so $a=d=\varepsilon$ for some $\varepsilon \in \{1,-1\}$. Therefore
\begin{align*}
\gamma =
\begin{pmatrix}
\varepsilon & b \\
0 & \varepsilon
\end{pmatrix}
=
\varepsilon I\, T^{\varepsilon b}.
\end{align*}
Since $S^2=-I$, the matrices $I$ and $-I$ both lie in $G$, and $T^{\varepsilon b}\in G$. Hence $\gamma\in G$ in this case.
Now suppose $c\neq 0$. We show how to reduce $|c|$. If $|a|<|c|$, then left-multiplication by $S$ sends the first column to $(-c,a)^\top$, so the new lower-left entry has absolute value $|a|<|c|$. If $|a|\ge |c|$, the division algorithm gives an integer $q$ such that
\begin{align*}
r:=a+qc
\end{align*}
satisfies $|r|<|c|$. First left-multiply by $T^q$, which changes the first column to $(r,c)^\top$. Then left-multiply by $S$, which changes it to $(-c,r)^\top$. The new lower-left entry is $r$, and therefore its absolute value is strictly smaller than $|c|$.
This gives a strict descent in the nonnegative integer $|c|$. After finitely many repetitions, the lower-left entry becomes $0$. Hence there exists $A\in G$ such that
\begin{align*}
A\gamma =
\begin{pmatrix}
\varepsilon & m \\
0 & \varepsilon
\end{pmatrix}
\end{align*}
for some $\varepsilon\in\{1,-1\}$ and $m\in\mathbb{Z}$. The triangular case already proves $A\gamma\in G$. Since $A\in G$ and $G$ is a subgroup, $A^{-1}\in G$, and therefore
\begin{align*}
\gamma=A^{-1}(A\gamma)\in G.
\end{align*}
Thus every element of $SL_2(\mathbb{Z})$ lies in $G$, so $SL_2(\mathbb{Z})=G$.
[/guided]
[/step]
[step:Deduce invariance under inverse generators]
The identity matrix $I \in SL_2(\mathbb{Z})$ satisfies $f|_k I=f$ by the definition of the slash operator. Since $SS^{-1}=I$, the right-action identity gives
\begin{align*}
f = f|_k I = f|_k(SS^{-1}) = (f|_k S)|_k S^{-1} = f|_k S^{-1}.
\end{align*}
Similarly, since $TT^{-1}=I$,
\begin{align*}
f = f|_k I = f|_k(TT^{-1}) = (f|_k T)|_k T^{-1} = f|_k T^{-1}.
\end{align*}
Thus $f$ is invariant under $S$, $S^{-1}$, $T$, and $T^{-1}$.
[/step]
[step:Propagate invariance through a word for $\gamma$]
Let $\gamma \in SL_2(\mathbb{Z})$. Since $S$ and $T$ generate $SL_2(\mathbb{Z})$, there exist an integer $N \ge 0$ and matrices
\begin{align*}
g_1,\dots,g_N \in \{S,S^{-1},T,T^{-1}\}
\end{align*}
such that
\begin{align*}
\gamma = g_1g_2\cdots g_N,
\end{align*}
with the convention that $N=0$ means $\gamma=I$.
We prove by induction on $j \in \{0,1,\dots,N\}$ that
\begin{align*}
f|_k(g_1g_2\cdots g_j)=f,
\end{align*}
where the product for $j=0$ is $I$. The case $j=0$ is $f|_k I=f$. Suppose the assertion holds for some $j<N$. Using the right-action identity and the fact that $f|_k g_{j+1}=f$, we obtain
\begin{align*}
f|_k(g_1\cdots g_jg_{j+1})
&= (f|_k(g_1\cdots g_j))|_k g_{j+1} \\
&= f|_k g_{j+1} \\
&= f.
\end{align*}
By induction, $f|_k(g_1\cdots g_N)=f$. Since $g_1\cdots g_N=\gamma$, this gives
\begin{align*}
f|_k\gamma=f.
\end{align*}
As $\gamma \in SL_2(\mathbb{Z})$ was arbitrary, the theorem follows.
[guided]
Fix an arbitrary matrix $\gamma \in SL_2(\mathbb{Z})$. The generation result says that $\gamma$ can be written as a finite word in the four matrices $S$, $S^{-1}$, $T$, and $T^{-1}$. Thus there are an integer $N\ge 0$ and matrices
\begin{align*}
g_1,\dots,g_N \in \{S,S^{-1},T,T^{-1}\}
\end{align*}
such that
\begin{align*}
\gamma=g_1g_2\cdots g_N.
\end{align*}
If $N=0$, this means $\gamma=I$.
We now move through this word one letter at a time. Define, for each $j\in\{0,1,\dots,N\}$, the partial product
\begin{align*}
\gamma_j :=
\begin{cases}
I, & j=0,\\
g_1g_2\cdots g_j, & 1\le j\le N.
\end{cases}
\end{align*}
We prove by induction on $j$ that
\begin{align*}
f|_k\gamma_j=f.
\end{align*}
For $j=0$, this is $f|_k I=f$, which follows directly from the definition of the slash operator.
Assume $f|_k\gamma_j=f$ for some $j<N$. Since $g_{j+1}$ is one of $S$, $S^{-1}$, $T$, or $T^{-1}$, the previous step gives
\begin{align*}
f|_k g_{j+1}=f.
\end{align*}
Using the right-action identity,
\begin{align*}
f|_k\gamma_{j+1}
&= f|_k(\gamma_j g_{j+1}) \\
&= (f|_k\gamma_j)|_k g_{j+1} \\
&= f|_k g_{j+1} \\
&= f.
\end{align*}
This proves the induction step.
Taking $j=N$, we get
\begin{align*}
f|_k\gamma_N=f.
\end{align*}
Since $\gamma_N=\gamma$, this is exactly
\begin{align*}
f|_k\gamma=f.
\end{align*}
Because the original choice of $\gamma \in SL_2(\mathbb{Z})$ was arbitrary, $f$ is invariant under every element of $SL_2(\mathbb{Z})$.
[/guided]
[/step]