Originally 'doolally tap', meaning unbalanced state of mind.
The spelling of dolally is fairly arbitrary and is seen as, 'go doolally', 'go doo-lally', 'go doolali' etc. This arbitrariness is due to it being an Anglicized version of an Indian place name rather than any English word.
The term is British Army slang, from the Deolali sanatorium, Marashtra, India and is first cited in Fraser & Gibbons', Soldier & Sailor Words, 1925:
"Deolali tap (otherwise doolally tap), mad, off one's head. Old Army."
Frank Richards, (Francis Philip Woodruff) was a soldier in the First World War and wrote a classic account of it in Old Soldiers Never Die. Richards was also a veteran of the Indian campaign, which he wrote about in in Old Soldier Sahib, 1936:
"Time-expired men sent to Deolalie from their different units might have to wait for months before a troop-ship fetched them home... The well-known saying among soldiers when speaking of a man who does queer things, ‘Oh, he's got the Doo-lally tap,’ originated, I think, in the peculiar way men behaved owing to the boredom of that camp."
The phrase is quite archaic now, even in its 'go Dolally' form. The tap is now rarely heard, but hasn't quite died out of everyday use. Francis Marion Crawford, in his Mr. Isaacs, 1882, makes the meaning of the word clear:
"Unless I feared the tap, the bad kind of fever which infects all the country at the base of the hills."
Other phrases first cited in Fraser and Gibbons: