Madara might be my fav character of all time in the series. However, this just means that he hadn't figured out what he should do at that point of time to give Madara a good defeat (not saying he didn't also hint at him being the strongest villain in the manga possibly). Unfortunately, he started rushing things to end the manga on the 700 chapters mark, and didn't give him a good death at all.
It's like this, Kishi probably didn't know how to defeat/kill Sasori with @&$&ing Chiyo and Sakura, so he threw an asspull out there. Same thing with a lot of the Akatsuki members, he didn't know how Sasuke at that time would take out Deidara without showing Kirin (for the sake of the hype vs Itachi), so he killed Deidara off by blowing him up. Kisame suffered a similar fate though it isn't much of an asspull rather than a ridiculous coincidence by having him not be able to absorb chakra by fighting a Guy who uses tainutsu(didn't even try to intend that at first). He also decided to give Naruto some hype/feat since he was so weak at the time and Sasuke would have stomped him in early part 2, he had a 93year old wise shinobi get tricked by a shadow clone plus a close range FRS. Maybe if that technique was made to be thrown from the start he woulda gotten a nod from me, and maybe if like the alternate scenario (as Kakashi even said), Kakashi would catch him off guard and snipe the rest of his hearts with kamui. Don't even get me started on the war fights where a bunch of fodders managed to seal a bunch of Kage/Sanin/elite jonin level ninjas.