Looks to me like that black plastic piece is the factory wind deflector. It is supposed to fold down and get tucked under the moonroof glass when it is in the closed position yours must be malfunctioning/ stuck. I dont have any pictures of mine and it is night time but I know there have to be some pictures of 4runner roofs in the pic thread.
Anyway try having someone hold/push the black plastic wind deflector at the front of the opening downward while the moonroof is being closed it should slide right over it.
Hope you find out what is causing the issue, wish I could be of more help.
__________________
2000 "The Silver Legacy 2" Highlander Edition, 5speed 4x4
2000 "The Silver Legacy" Highlander Edition, 5speed 4x4 RIP
1996 Stellar Blue 5 Speed Sold