What you are describing is more than a typical YouTube or Safari freeze.
The video stops and shows the spinning beachball while the audio continues, then the mouse and keyboard stop responding and you have to hold the power button to regain control.
Since this is happening several times a day and sometimes within minutes of restarting the iMac, it is worth investigating as a system-level problem rather than assuming it is simply YouTube.
The fact that it started after upgrading to macOS 27.0.1 is certainly relevant, although that timing alone does not show that the update is the cause.
The next time it happens, before forcing a shutdown, try Command–Option–Escape.
If the Force Quit window appears, or if the pointer still moves, make a note of that.
If neither the keyboard nor mouse responds, that tells us the problem is extending beyond the YouTube page or Safari window.
The most useful test is then to watch YouTube in another browser, such as Firefox or Brave.
If Safari freezes but another browser does not, that would point toward Safari or something Safari uses. If the entire Mac becomes unresponsive in another browser too, the investigation needs to go beyond Safari.
If there is commercial VPN used, that is another worthwhile variable to test.
Compare YouTube with the VPN connected and then completely disconnected, keeping everything else the same.
Apple notes that VPN and other network software can affect Safari and Internet use. (support.apple.com)
That makes the VPN worth testing, although there is no basis yet for saying that it is responsible for the keyboard and mouse failure.
If the problem appears to be Safari-specific, try YouTube in a Private Window and temporarily disable Safari extensions.
Apple recommends these steps when troubleshooting Safari. (support.apple.com)
If the Mac continues to become completely unresponsive regardless of the browser or VPN, the next steps would be Safe Mode and, if necessary, Apple Diagnostics.
Apple Diagnostics reference codes
Apple explains that Safe Mode can help identify problems caused by software that loads at startup, while Apple Diagnostics can help identify hardware problems.
It would also be sensible to temporarily disconnect any non-essential external devices while testing. Apple includes this among its troubleshooting steps for unexpected Mac problems. (support.apple.com)
I would change only one thing at a time so we can tell what, if anything, makes a difference. If the Mac becomes completely unresponsive again, a forced shutdown may be necessary.
The important thing to establish is whether the complete loss of keyboard and mouse control happens only with Safari/YouTube, also occurs with another browser, or occurs regardless of the browser and VPN. That will give us a much clearer direction for the next step.