There are a number of reasons why your phone could restart unexpectedly. It could range from being an issue with a particular app you have installed to even a hardware with your device. If you notice an unexpected restart happening again, enable developer options and generate a bug report immediately afterwards.
You can then ask here to share the bug report with a trusted member of the GrapheneOS development team. Better not to post the bug report publicly as it can contain PII.
As I say, there are many reasons why this could occur, and most of them don't have anything to do with your device being compromised. That said, you can always verify the integrity of your device and the OS by performing verification with the Auditor app for additional piece of mind.