What is the meaning of [Though this be madness, yet there is method in it]

Reason behind apparent folly or disorder.

This line derives from Shakespeare’s Hamlet, 1602:

LORD POLONIUS [Aside]:
Though this be madness, yet there is method in ‘t. Will you walk out of the air, my lord?