WARNING: This page is about a different car, the 2010 BMW M5, 2009 BMW M5, 2008 BMW M5, 2007 BMW M5, and 2006 BMW M5. However, it is still accessible from the selected car via links, so may be relevant.
Unfasten plug connection (1) and disconnect.
Unlock locking clip (2) in direction of arrow and remove socket housing for rear light (3) from rear light (4).
Fig 1: Identifying Plug Connection And Locking Clip