Its a bit of both.
The rubber is attached to the zip in window. It ages, starts to lose it shape and ultimately start to break away from the window.
You can see the threads from the top starting to fry a little bit.
At this stage, people start using all sorts of glues to try and fix the problem. It works for a while. If you are going to sell the car soon, then gluing may be a good option.
If you want to keep the car, It's time to think about fixing the rear window properly before you mess it up with glues.
Check the stitching around the window, those white/grey stitches. How many are missing? There is one missing in your photo. The ones to really look at the in the middle of the sides where the fold happens. Those stitches hold in the window zip. If needed they can be hand sewed with 2 needles, one inside and the other outside. Best done with the window removed.
As for the window, there are several options. Ones with a similar rubber bead and ones with a glue over flap. If the frying is not too bad, then a window with a rubber bead works well. If the frying is getting bad, then going to a window with a glue over flap works well. I just jump straight to the Glue over flap window in all cases.
I use the Emiata Z3 rear window. Have fitted 3 now. It has a thicker clear plastic window that lasts a long time and the glue over flap that seals very well and looks good. The product quality is great and it zips in well. The window kit even comes with the Zip pulls that you need to do the job. There is one in my 2.0L Z3, which has been there for over 10 years and still looks good.
Replacement Rear Vinyl Window for BMW Z3 Z-3 M Roadster MRoadster.
www.emiata.com