By what you describe, the drive cable housing is worn out and the cable pops out when under a compression load. This will probably require a new head end housing. I am not sure if the drive cable is replacable as a separate item. What I have seen is pictures of the whole assembly, not components. The guide channels for the roof panel probably are dirty as well. If you've got the headliner off, then you're halfway home. Check on what's available for parts. Maybe someone else has more experience with these components. On my 87 300E, roof panel was noisy when operating. Removed headliner and cleaned/lubed the tracks. Problem solved. Good luck...
1987 BMW 325