Dear M.Sameer: It seems that you are missing that the $n+\ell$ Madelung rule is not an exact result derived from first principles, but rather a rule of thumb, that holds for, say, approximately 95 percent of all the elements, with important exceptions, cf. this wikipedia page. Nevertheless, there are semi-rigorous theoretical arguments why such a rule of thumb should hold to a good approximation.
• That isn't true. The $5s$ orbital (usually) has a lower energy than the $4d$, so electrons will start filling the $5s$ orbital before they start filling the $4d$ orbital. – John Rennie Feb 28 '15 at 6:42