If im reading what your saying correctly, ive had the same problem. it about gave me a heart attack when i opened my sunroof and it was raining and it wouldnt close.... I finally figured out that My grease got old and it was filled with dust and debris from offroading and it all added up making a mess up there, Simple solution, I cleaned it up and I squirted heavy amounts of some HD marine grease in there all over,( helped with smoothness) to make it close, hold down the black thing thats pops up when the glass goes back in the front with your hand and poke the close button with the other. should work
Stealership quoted me 1500$ for a new sun roof, This is much easier and it still works lol