If it is not the logout after idle 'n' minutes option, then I would lean toward the system actually panic'ing when waking from sleep.
If Applications -> Utilities -> Terminal
uptime
19:04 up 9 days, 6:24, 6 users, load averages: 2.54 2.69 2.60
Says the system has only been up for a few minutes after waking, then I would assume it rebooting because of a system panic.
As you can see from my uptime, my Mac has been up for 9 days, 6 hours, and 24 minutes. I put this Mac to sleep every night, and all my apps are still there in the morning. My network connections have been broken (VPN into my company network, my ssh connections to work computers, etc... are all broken, but I expect that when I put my Mac to sleep). However, all my previous apps are still running (web browser, email, Activity Monitor, System Preferences, terminal emulator, Podcast app, backup utility, etc... are all still there).
If you do have a short uptime, then it might be a battery issue (unlikely on an M2 MacBook Air, but this has been known to happen on Macs with older batteries). It could 3rd party software (less of an issue these days as Apple is really pushing for not kernel extensions), it could still be 3rd party software, as I've seen anti-virus packages using the Apple provided hooks cause the Apple software to panic. It could be external hardware, as I've seen keep alive times timeout triggering panic because external hardware was too slow to respond to software probes. The point is, there can be lots of reasons the Mac could be forced to reboot, and if uptime is from the time you woke up the Mac, they it would appear a reboot occurred.
I do know of an app called "Quitter" that will quit or hide idle apps you specify, but you would have had to install the 3rd party Quitter app and configure it for the apps to quit or hide. If your "uptime" is long, then you might want to review what 3rd party apps you have installed. EtreCheck can give you a list of 3rd party apps that run in the background that you can review what additional services they perform.