Although there is already an accepted answer, I'll provide a different point of view here.
It is important to keep in mind that the imaginary time is periodic, which means fields satisfy periodic(or anti-periodic) boundary conditions (the reason is because we use imaginary time path integral to represent the partition function, which is $\mathrm{Tr}\, e^{-\beta H}$). Therefore, the correlation functions also obey the same kind of periodic conditions under the shift $\tau\rightarrow \tau+\beta$, which is why the Matsubara frequencies are $\frac{2\pi n}{\beta}$ for $n\in\mathbb{Z}$ for bosonic fields, and $\frac{(2n+1)\pi}{\beta}$ for fermionic fields. So if $|\tau_A-\tau_B|$ is larger than $\beta$, all you need to do is to fold it back by adding or subtracting several $\beta$'s, just as one would do to any periodic functions.
EDIT: The periodicity of Green's function can be explicitly derived, without using the path integral representation. After all, the path integral representation is designed to be consistent with the operator formalism.
Let's assume $A$ and $B$ are bosonic, so I do not need to keep track of the fermionic sign. For concreteness, consider $-\beta<\tau<0$ and
$$ G(\tau)=\langle \mathcal{T} A(\tau)B(0)\rangle=\mathrm{Tr}[e^{-\beta H}B(0)e^{\tau H}A(0)e^{-\tau H}]=\mathrm{Tr}[ e^{\tau H}A(0)e^{-\tau H}e^{-\beta H}B(0)]\\ =\mathrm{Tr}[e^{-\beta H}e^{(\tau+\beta) H}A(0)e^{-(\tau+\beta) H}B(0)]=\langle \mathcal{T} A(\tau+\beta) B(0)\rangle =G(\tau+\beta) $$
Here we use the cyclic property of the trace.