Belgium, France, Spain and certain countries in Continental Europe, share a common immigration zone called the Schengan agreement. You clear immigration at the first port of call (BRU or CDG) and there is no need to clear immigration again at MAD.
Whether you have to collect you bags to clear customs is strictly dependant on whether United will inter-line your bags directly to the airline you are flying to MAD with.
So Air France via CDG to MAD should be relatively straight forwards. If you want to fly United, you might have to connect via Spanair which is also part of the Star Alliance so that your bags can be checked straight to.
Not sure if United would inter-line with Brussels Airlines. You need to allow at least 2/3 hours if your bags are not checked through