Body text special characters are escaped
Assuming by my normal HTML becomes you mean the escaped HTML is rendering on the front end, you're probably just resetting the format for the body field with this line
$entity-&gt;set('body', $body_encoded);

You can target the value directly instead like this (and you shouldn't need to encode/decode anything):
$entity-&gt;body-&gt;value = preg_replace('/(?:https:\/\/)?(?:http:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)/', '&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/$1&quot; title=&quot;YouTube video player&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen&gt;&lt;/iframe&gt;', $node_body);

If that isn't working you can try setting the format too:
// Possibly change 'full_html' to whatever's appropriate for your site.
$entity-&gt;body-&gt;format = 'full_html';