[Below we use congruence (modular) arithmetic, notably the congruence sum and product rules. Readers unfamiliar with congruences please skip ahead to "Without mod" below, and note that the notation $\ a\mid b\ $ means $\ a\,$ divides $\,b,\,$ i.e. $\, an = b\,$ for some integer $\,n$].
Let's derive the test. Let $\, n = 10b + a\,$ for $\,a = $ units digit. Working $\!\bmod 7,\,$ the idea is to simplify $\,b$'s coefficient $\,10\,$ to $\,1,\,$ by scaling $\,n\,$ by $\,\color{#c00}{10^{-1}\equiv -2},\ $ by $\, \color{#c00}{-2\cdot 10\equiv 1}\pmod{\!7},\,$ i.e.
$$\begin{align} 7\ \mid\ 10b+a\ \,&\\
\iff\qquad\! 10 b+a\ \,& \equiv 0\pmod{\!7}\\
\color{red}\iff \color{#c00}{-2}\,(\color{#c00}{10}b+a)&\equiv 0\ \ \ \ {\rm by\ \ } {-2} \times \rm prior\\
\iff\qquad\ \ b\color{#0a0}{-2}a\ &\equiv 0\ \ \ \ {\rm by}\ \ \color{#c00}{{-}20\equiv 1}\\
\iff\qquad\ \ b\color{#0a0}{+5}a\ &\equiv 0\ \ \ \ {\rm by}\ \ \color{#0a0}{{-}2\ \equiv\ 5}
\end{align}\qquad\qquad$$
$${\rm so}\ \quad \bbox[6px,border:1px solid #c00]{7\mid 10b+a\iff 7\mid b-2a\iff 7\mid b+5a}\qquad\qquad\qquad $$
The same works for any divisor $\,d\,$ coprime to $10$ using $\,\color{#c00}{c\equiv 10^{-1}\pmod{\!d}}$
$$\begin{align} d\ \mid\ 10b+a\ \,&\\
\iff\qquad\! 10 b+a\ \,& \equiv 0\pmod{\!d}\\
\color{red}\iff \ \ \ \color{#c00}c\,(\color{#c00}{10}b+a)&\equiv 0\ \ \ \ {\rm by\ \ } c \times \rm prior\\
\iff\qquad\ \ b+\color{#c00}{c}a\ &\equiv 0\ \ \ \ {\rm by}\ \ \color{#c00}{10c\equiv 1}\\
\end{align}\qquad\qquad\ \ \ $$
$${\rm so}\ \quad \bbox[6px,border:1px solid #c00]{d\mid 10b+a\iff d\mid b+\color{#c00}c\:\!a,\,\ \color{#c00}{c\equiv 10^{-1}}\!\!\!\!\!\pmod{\!d}}\qquad\qquad\quad $$
The $\color{#c00}{\rm second}\!\!\color{red}{\iff}$ is bidirectional since scaling by an invertible element is an invertible operation: $ $ to invert scaling by $\color{#c00}{-2}\,$ we scale by its inverse $\color{#c00}{10}$, i.e. $10\,\times$ the second congruence yields the first. Generally - like equations - scaling a congruence by an invertible number yields an equivalent congruence (recall a modular integer is invertible $\!\iff\!$ it is coprime to the modulus, by Bezout).
This method works for any coprime divisor $\,d\,$ and radix $\,r\,$ exactly as above, i.e.
$$\bbox[6px,border:1px solid #c00]{d\mid r\:\!b\!+\!a\iff d\mid b\!+\color{#c00}{\hat r}a,\ \ {\rm for}\ \ \color{#c00}{\hat r \equiv r^{-1}}\!\!\!\!\!\pmod{\!d}}\qquad $$
Without mod $\ $ Eliminating congruence language above yields more elementary proofs
By $\color{#90f}{\rm Lemma}$: $\ \gcd(\color{#c00}{7,-2})=1\, $ so $\, 7\mid 10\,b\,+\,a\ \iff\ \ \color{#c00}{7\,\mid\! {-}2}(10b\!+\!a)\!\color{#0a0}{+\!7(3b)} = b - 2a$
By $\color{#90f}{\rm Lemma}$: $\ \gcd(\color{#c00}{7,\,5})\:=\:1\,$ so $\ 7\mid 10\,b\,+\,a\ \iff\,\ \color{#c00}{7\, \mid\,\ 5}\:(10b\!+\!a)\!\color{#0a0}{-\!7(7b)} =\, b +5a$
$\color{#90f}{\bf Lemma}\ $ If $\, \gcd(\color{#c00}{7,c})=1\,$ then $\ 7\mid n\!\!\!\!\overset{\rm EL\!\!}\iff\!\! \color{#c00}{7\mid c}n\!\!\iff\! \!\color{#c00}{7\mid\, c}\,n \color{#0a0}{+7\, m}\, $ by $\rm EL = $ Euclid's Lemma
Remark $ $ The divisibility test works for all integers $\,a,b\,$ (not only digits in decimal radix rep), e.g. $\,a,b\,$ can be negative. Said in fractions: $\,10b+a\equiv0\iff b\equiv -a/10\equiv 2a\pmod{\!7}.\,$ Note that the special case $\,a\equiv -1\,$ yields the inverse of $10,\,$ namely $\,1/10\equiv -2.\,$ Exactly the same method as above works for any divisor $\,d\,$ coprime to the radix $\,r\,$ $(\!\!\iff\! r\,$ is invertible $\!\bmod d)$.
Alternatively we can use the universal divisibility test which - unlike the above divisibility test which computes only a binary truth value - has the advantage of computing the remainder, so can be used to check arithmetic, etc, as in casting out nines and elevens.
Below is a common variant of such divisibility tests, e.g. see here (deleted), or here (brilliant.org)
Theorem $ $ If $\,10c\!-\!ud=\color{#c00}1\,$ then $\,10t\!+\!u\mid 10b\!+\!a \iff 10t\!+\!u\mid b\!+\!(c\!+\!dt)a,\,$ e.g.
$$\!\begin{align}&n=10t\!+\!1 \mid 10b\!+\!a\iff n\mid b\!+\!(1\!+\!9t)a
\iff n\mid b-t\:\!a\\[.1em]
&n=10t\!+\!3\mid 10b\!+\!a\iff n\mid b\!+\!(1\!+\!3t)a\\[.1em]
&n=10t\!+\!7\mid 10b\!+\!a\iff n\mid b\!+\!(5\!+\!7t)a
\iff n\mid b\!-\!(2\!+\!3t)a\\[.1em]
&n=10t\!+\!9\mid 10b\!+\!a\iff n\mid b\!+\!(1+\:\!t)a\end{align}\qquad\ $$
Proof $\bmod \!10t\!+\!u\!:\ 10\,(b\!+\!(c\!+\!dt)a) = 10b\!+\!(\color{#c00}1)a\,$ by $\,10t\equiv -u,\,$ hence
$$n=10t\!+\!u\mid 10b+a\iff \color{#0a0}{n\mid 10}\,(b\!+\!(c\!+\!dt)a)\iff n\mid b\!+\!(c\!+\!dt)a\qquad$$
follows by Euclid's Lemma, since $\color{#0a0}{(n,10)} = (10t\!+\!u,10)=(u,10)=\color{#c00}1.\ \small\bf QED$
$10c\!-\!ud=1\Rightarrow\bmod 10\!:\ d\equiv -u^{-1},\,$ e.g. we can choose $\,d = -u^{-1}\bmod 10.$
E.g. $\,u = 1\Rightarrow\, d\equiv -1/1\equiv 9 ,\,$ so $\,c = (1\!+\!ud)/10 = 1,\,$ so
$\qquad\qquad\begin{align}n=10t\!+\!1\mid 10b\!+\!a\iff& n\mid b\!+\!(1\!+\!9t)a\\
\iff& n\mid b-t\:\!a\end{align}$
E.g. $\,u = 3\Rightarrow\, d\equiv -1/3\equiv 9/3\equiv 3,\,$ so $\,c = (1\!+\!ud)/10 = 1,\,$ so
$\qquad\qquad n=10t\!+\!3\mid 10b\!+\!a\iff n\mid b\!+\!(1\!+\!3t)a$
E.g. $\,u = 7\Rightarrow\, d\equiv -1/7\equiv 9/(-3)\equiv -3\equiv 7,\,$ so $\,c = (1\!+\!ud)/10 = 5,\,$ so
$\qquad\qquad\begin{align}n=10t\!+\!7\mid 10b\!+\!a\iff& n\mid b\!+\!(5\!+\!7t)a\\
\iff& n\mid b\!-\!(2\!+\!3t)a\end{align}$
E.g. $\,u = 9\Rightarrow\, d\equiv -1/9\equiv 9/9\equiv 1 ,\,$ so $\,c = (1\!+\!ud)/10 = 1,\,$ so
$\qquad\qquad n=10t\!+\!9\mid 10b\!+\!a\iff n\mid b\!+\!(1\!+\!t)a$