As already mentioned by Zedainder, while modern Macs are generally very reliable, there are still a few scenarios where macOS may intentionally shut the system down. Common causes include a thermal protection event, a low-level kernel panic, a brief power interruption at the USB-C port or power adapter, or macOS triggering a protective shutdown after a hardware or driver fault. These events can occur even when the battery health appears normal and the Mac is plugged in.
I suggest to help narrow this down, the best next step is to review the Mac’s system logs around the time the shutdown occurred. To do so, please open the Console app, and then look under Crash Reports, Log Reports, and the system.log for messages mentioning “shutdown cause,” “kernel panic,” “thermal,” or “Previous shutdown cause.”
In addition, if you previously enabled "Share Mac Analytics" in System Settings > Privacy & Security > Analytics & Improvements, you can review the "Mac Analytics Data" reports in the Console.
To make reviewing the logs easier, I suggest using some free utilities from The Eclectic Light Company.
In the meantime, I’d suggest that you confirm that you’re using an Apple or known-good power adapter and cable, ensuring the Mac has adequate ventilation, and checking whether this happens again. If the logs indicate a hardware-related shutdown or the behavior repeats, the next step would be Apple Diagnostics or an Apple Support evaluation.