Fixed it with the help of claude, it quickly helped me diagnose the issue and fix it. The drivers for the discrete nvidia graphics card had suspend disabled. Enabling it enabled automatic suspend when closing the lid.