Assume there is a solution that is guaranteed to terminate. Then there exists some $n$ such that at most $n$ samples of Rand5 are taken (use König's lemma to be precise). Then every path the algorithm takes is taken with a probability a multiple of $\frac1{5^n}$. No sum of such numbers equals $\frac17$ because $7$ does not divide $5^n$, hence there is no proceudre that terminates _for sure_. The best we can get is that it terminates _almost surely_ (i.e. with probability $1$); for example by rejection sampling as you describe it; or by interpreting the sequence of Rand5 outputs as the base 5 expansion of a real numbre in $[0,1)$ and stop as soon as it becomes clear in which interval $[\frac k7,\frac{k+1}7)$ we end up.