Why must the decimal representation of a rational number in any base always either terminate or repeat?

Look at the classical division algorithm: after you have exhausted the digits of the numerator, you will continue appending zeroes 'past the decimal point'. As the remainder is smaller than the divisor, it is finite and the same values will come back periodically. The period length of the decimals cannot exceed the value of the divisor minus $1$.

Base $10$ example, $83/7$:

$83\div 7=10$, remainder $1$ ($=8-7$).

$83\div 7=11$, remainder $6$ ($=83-7\cdot11$).

$83\div 7=11.8$, remainder $4$ ($=830-7\cdot118$).

$83\div 7=11.85$, remainder $5$ ($=8300-7\cdot1185$).

$83\div 7=11.857$, remainder $1$ ($=83000-7\cdot11857$).

$83\div 7=11.8571$, remainder $3$ (=$\cdots$).

$83\div 7=11.85714$, remainder $2$.

$83\div 7=11.857142$, remainder $6$.

$83\div 7=11.8571428$, remainder $4$.

$\cdots$

Conversely, when you have a periodic number, if you shift it left by one period and subtract the original, you obtain a terminating number by cancellation of the decimals.

$$11857142.8571428571428571428\cdots-11.8571428571428571428\cdots=11857131,$$ hence the number is $$\frac{11857131}{999999}=\frac{83}7.$$


Let $a\operatorname{div}b$ be the integer part of division of $a$ by $b$. (Example: $7\operatorname{div}5 = 1$)

Let $a\bmod b$ be the remainder part of division of $a$ by $b$. (Example: $7\bmod 5 = 2$)

Suppose $a < b$. When you perform division what basically you do is these steps:

$$\begin{align} & i_1 = (10\cdot a)\operatorname{div}b \ \ \ \text{and}\ \ \ r_1 = (10\cdot a)\bmod b \\ & i_2 = (10\cdot r_1)\operatorname{div}b \ \ \ \text{and}\ \ \ r_2 = (10\cdot r_1)\bmod b \\ & i_3 = (10\cdot r_2)\operatorname{div}b \ \ \ \text{and}\ \ \ r_3 = (10\cdot r_2)\bmod b \\ & i_4 = (10\cdot r_3)\operatorname{div}b \ \ \ \text{and}\ \ \ r_4 = (10\cdot r_3)\bmod b \\ & \quad\vdots \end{align}$$

If division result digits terminates, then division result is: $0.i_1 i_2 i_3\ldots i_k$, where $k$ is some finite number. This happens because $10\cdot r_k$ is divisible by $b$.

If division result digits do not terminate, then division result is: $0.i_1 i_2\ldots i_k i_1 i_2\ldots i_k i_1 i_2\ldots i_k\ldots$, where $k$ is some finite number. This happens because non of $10\cdot r_1, 10\cdot r_2, \ldots, 10\cdot r_k$ is divisible by $b$, but since $b$ is finite number remainders bus appear more than once and therefore when it appears for the second time digits start to repeat.