It sounds like there may be an issue with the sunroof control module or the sunroof switch itself. It's possible that a glitch or fault in the module is causing the sunroof to open when the car is shifted into park. Alternatively, the sunroof switch may be stuck or malfunctioning, causing it to activate when it shouldn't.
To troubleshoot the issue, you could try resetting the sunroof control module. This can often resolve minor glitches or errors. To do this, you'll need to locate the module (it's usually located near the sunroof itself or in the headliner). Once you've found it, you can try disconnecting the battery and then waiting a few minutes before reattaching it. This will allow the module to reset itself.
If resetting the module doesn't fix the problem, you may need to take the car to a mechanic or dealership for further diagnosis. They'll be able to determine the root cause of the issue and recommend the necessary repairs. In the meantime, you can try using the sunroof switch as little as possible to avoid accidentally activating it.