REPEAT() and RPAD() results in a subquery get truncated if the length parameter is between 32768 and 65536 for 2-byte UTF-8 sequences, or between 21845 and 65535 . Below and above that point the result is correct.
This is not a problem of the length function in the outer query, it is already the string returned from the inner query that gets truncated as can be seen with
Looks as if the intermediate result length is calculated by character count and not by byte length, and so the wrong data type seems to be used to store the intermediate result. E.g. when using a unicode character that has a 3 byte UTF-8 representation: