Are you asking how to prove this specific divisibility rule for $13$? If so, it's not hard with modulo arithmetic.
To separate the units place from the rest of the number, you can express it as $10x + y$, where $y$ represents the units place.
$10x + y = 13x - 3x + 13y - 12y = 13(x+y) -3(x+4y) \equiv -3(x+4y) \pmod{13}$
Since $3$ is coprime to $13$ (no factors other than $1$ in common), if $x+4y \equiv 0 \pmod{13}$ (another way of saying $x+4y$ is divisible by $13$), then $10x + y \equiv 0 \pmod{13}$, which proves the divisibility rule.
You can now express that rule in a simple algorithm: strip off the last digit, multiply it by $4$ and add that to the remaining number. If the new number is divisible by $13$, then so was the original number.
You can also find similar (i.e. slightly "ugly") rules for divisibility by $7$ and other odd primes using similar methods. For instance, for $7$, the rule is strip off the last digit, double it and subtract that from the remainder of the number. If the new number is divisible by $7$, so was the original. ($10x + y = 7(x+y) + 3(x-2y) \equiv 3(x-2y) \pmod 7$).