How can i verify a certificate to root?
Your code should work.

However you (implicitely?) assume the certificate uses PSS padding for the RSA signature. While this is possible, it is extremely rare in practice, you should try validation using PKCS#1 v1.5 signature padding instead.

Converted my last comment to an answer because it apparently solved the problem.