I have an E36 328i and the tail light sits down on the metal, trapping water, and started to rust. I noticed the tail light on the X5 was doing the same. When I washed it, that area would trap water and take numerous swipes to dry. It was heading the way of the E36. Plus it wasn't aligned with the tail gate, so it needed to be adjusted
Here is how they sat at the start. You can see the lower gap was tight and the upper gap was not very BMW-ish.
You can gain access to the fastening nuts by opening the two side panels in the rear. Loosen the nuts to the end of the stud and press the nuts towards the rear of the car to loosen the tail light from the vehicle.
Adjust and hold in place from the outside and re-tighten the nuts. Torque is low, so don't overdo it. Gap should now be more consistent top to bottom, aligned with the tail gate and NOT trap water any longer.