Reply from Siteground below. It wasn't Rank Math after all, but I think you knew that!
Thanks for all your help.
I have tried to insert the code in the .htaccess file of the website but it is breaking the application and the website returns error 500 when this rule is present.
The actual issue was that your index.php file did not begin with an opening php tag but with a blank space. I delete the row with the blank space and now the sitemap is loading properly: