Integers(13)(2) is 2 mod 13. Computing Integers(13)(2)**r starts by
computing r % 12 - much faster than doubling alone (after such a reduction one
can do doubling, as is done by GMP, used in the implementation).
And that's how it's implemented in Sage, too.
The error you see is different - it's due to an incorrect conversion
attempt in __pow__()
in rings/finite_rings/integer_mod.pyx
this works:
sage: set_random_seed(1);a=(Integers(13)(2))**(randint(2,2**4000-1) % 12); a
4
Thanks for the report. I've opened
https://github.com/sagemath/sage/issues/36080