This means to be dressed very smartly or extravagantly. But why 'to the nines?'
Many years ago, when Britain had Imperial currency - also called 'old money' which was in Pounds, shillings and pence, the expensive seats in a cinema or theatre were high up and cost ninepence. It was something special to go there and you needed to be dressed very smartly - up to the nines!
And, what more important theatrical occassion than the big speech from Hamlet!