Its drains are blocked.
And the solution is extremely simple.
Open the full sunroof and find the tiny drain holes in the corners of the rail channel.
Some cars has only two drain holes in the front and some has only two drain holes in the rear and some cars has 4 drain holes. Two in the front and two at the rear.
From your pictures it seems your car has 4 drain holes in the sunroof channel.
Once you locate those drain holes, the best way is the use compressed air. (The same pressure which we used to blow the air filters).
Doing so will clear the drain channel.
After that pour some water on the channel and will see if its draining well. Usually drain holes pipes open at close to the front & rear wheel. You can see the water dripping down close to the wheels.
Apply some silicon grease to the channel, close the sunroof and that’s all. Job is done well.