In reply to Kristal.

This has been reported in a Trac ticket as well: https://core.trac.wordpress.org/ticket/40951

The current proposed solution is to introduce a separate “HTML Code” widget that is dedicated for HTML as in your use case: https://core.trac.wordpress.org/ticket/40907

As it stands right now, the Text widget's behavior has been made to align with the post editor. HTML written for the post editor can be used in the Text widget and vice versa.