A few suggestions to help resolve this:
Leave the Mac in safe mode for a while. Does the problem occur? If it does not occur, that likely means that there is something installed that is conflicting with macOS and causing the problem. If the problem still occurs in Safe Mode, that makes it more likely that there is a hardware problem but it is not 100% definitive because these issues can still occur in Safe Mode, say if a file was removed that the Mac needs to run properly under your account/login.
- Download and run Etrecheck. Follow these instructions to post its report here in a reply:
How to use the Add Text Feature When Post… - Apple Community
You can read the report, it reveals no personal nor identifying info, only some technical details about how your Mac is configured. That info will be read by people here and they may be able to identify something for you to change or remove that will eliminate the problem.