It sounds like an OS issue. And you might need to do some debugging first. If you boot in safe mode, does the issue still occur?
Also, you have a couple of things (you probably already tried) here:
https://9to5mac.com/2020/01/20/mac-how-to-fix-and-restart-the-touch-bar/
If you haven't see if any of that works.
If you have a MacOS installation on a USB drive, you could also try installing MacOS on a different partition, just to see how it behaves on a fresh install. Alternatively, you could go into Guest account on your current installation and see if it still occurs.
To me, it sounds like a bug, ooor...something, a setting or an app that makes this freeze. But probably a bug.
So, as I was saying, this is what I would do. Test a few things to try to see where does the problem come from.
Unfortauntely I don't have an M1 Mac, so...I've never had this issue. Also, never heard of it before. But I know some people complained about issues with the Touch Bar before. So...that part is not new.
)
But anyway, hope this helps.