1650s, of unknown origin. A general term of abuse since 1920s.
The T-word occupies a special niche in literary history, however, thanks to a horrible mistake by Robert Browning, who included it in 'Pippa Passes' (1841) without knowing its true meaning. 'The owls and bats,/Cowls and twats,/Monks and nuns,/In a cloister's moods.' Poor Robert! He had been misled into thinking the word meant 'hat' by its appearance in 'Vanity of Vanities,' a poem of 1660, containing the treacherous lines: 'They'd talk't of his having a Cardinalls Hat,/They'd send him as soon an Old Nuns Twat.' (There is a lesson here about not using words unless one is very sure of their meaning.) [Hugh Rawson, "Wicked Words," 1989]