Why did my get mangled, and how can I keep from happening again?

This is a known bug with TinyMCE. That is the standard text editor in WP. When you hit refresh whilst editing a page it adds those tags to javascript. https://github.com/tinymce/tinymce/commit/5f320ac2acda15902b0488df1b7d85bf5c24ef94

However it is marked as fixed some time ago (2015) so perhaps your site is not up to date? Or of course perhaps it has resurfaced!