iMac Restarts during Sleep

My late 2020 Intel iMac running Ventura 13.2.1 has been restarting after it sleeps. If I leave the iMac unused this happens before the time I specify in System Settings for screen saver and turning off displays. I come back from a short break to find all the applications closed and the Lock Screen displayed (with both User and Test log ins).
I have reset SMC and started in Safe Mode but neither has helped. In the crash report section of Console there are two reports referencing “TextInputSwitcher” and “DTOCRHelper” (Devonthink) but I cannot interpret the reports to understand what happened.
Otherwise, my iMac is running almost perfectly. “Find my…” is not working for other devices despite being set up correctly, but I do not think these issues should be related.
Providing I do not leave it for any length of time my iMac works well. It is just frustrating having to log in and restart all apps for no obvious reason.
Can anyone suggest a cause and solution?

Did you look up TextInputSwitcher? Among other references, that is the name of a malware that is tagged as beginning 2 years ago. You may want to try running anti-malware software like Malwarebytes or one of the many commercial antivirus and anti-malware software packages. Do you keep your Mac’s software up to date? Only you know what you are doing on your Mac, but if it is not a malware problem, you could try identifying it by isolation. Turn off and quit ALL of the running apps, especially the ones that auto-start, and shut down the Mac. After cold restart, does same problem occur? If not, try to add an app at a time to see what happens. You may suspect one app more than others so start with that one. These can be hard problems to solve, not to mention that they can be caused by failing hardware.

If it were mine, I would bring it into my Apple store for a thorough checkup (I don’t care how far you have to drive).

EDIT TO ADD: If you can contact Apple support by phone, they may arrange for you to ship them your Mac, which is what an Apple store often decides they have to do anyway.)

Thank you karinyhus.
I have an Apple Store near my home and a good relationship with them. They have already offered to check my iMac if I cannot solve the problem myself. It is probably the sensible option to take it in to them to check. I have already screen-shared with Apple support and they could not find any problems.
I have malware detection on my iMac and that has not identified any threats.
I keep my OS and all my apps up to date with regular checks for those that do not update automatically. Having said that, OS 13.3 has just become available so I will install now.
Apart from this annoying “restart”, my iMac works normally with a wide range of apps.
If I find a solution I will post it here.
I use Ctrl-Space to launch Alfred, and I saw somewhere that Ctrl-Space was used with TextInputSwitcher (which I believe is an Apple OS app).

Problem Solved
There was a hidden feature in System Settings > Security and Privacy > Privacy tab > Advanced
to log out automatically after XX minutes.
This was set at 15 minutes. I am the only user on my iMac and cannot remember ever having accessed this setting. I did not know it existed until yesterday.
Anyway, I turned off the auto log out and my iMac now behaves exactly as I would expect. I would like to know how this auto log out got switched on.