This code appears to be working (not raising an exception) as early as Ruby 2.1.10:
This may be related to issue #12431 (Strange behavior of String#encode('UTF-8', 'UTF-8', ...) when the encoding of the source string is not UTF-8). This issue was fixed about 2.5 years ago (i.e. Ruby 2.4 timeframe), and the fix was backported back two versions (i.e. Ruby 2.3 and 2.2, if I count correctly).
I'm assigning this (even if maybe only temporarily) to Nobu, because he fixed issue #12431.