Popular wisdom attributes the derivation of this slang term for lavatory to Thomas Crapper (1836 - 1904), the supposed inventor of the flush toilet. Unfortunately, Thomas Crapper didn't invent the flush toilet. He holds nine patents for plumbing-related inventions, including three for water closets, but flush the lavatory, properly called the Silent Valveless Water Waste Preventer was patented in 1819 by Albert Giblin - and Queen Elizabeth I had a version of a flushing lavatory two hundred years earlier.
Nevertheless, Crapper is the name that people remember. He was certainly well-known in his day as a sanitary engineer. He had a thriving plumbing business and was sanitary engineer for several members of the royal family.
Like the widespread and misguided rejection of Nelson's deathbed quotation - 'kiss me Hardy', it has become commonplace to see any association of the name Crapper with toilets and defecation dismissed as an urban myth. Although that dismissal is strictly correct, people may be rushing to judgment by painting Crapper out of the picture entirely. The word crap, either as a noun or as a verb, doesn't appear in English before Crapper's lifetime. The earliest citation that refers to 'crap' as a reference to excrement is from an 1846 edition of Swell's Night Guide:
"Where's the plant, cully?"... "Fenced, in a dunniken."... "What? Fenced in a crapping ken?"
Swell's Night Guide was a magazine that circulated amongst the unruly elements of London society. By 'crapping ken', the author meant 'outside privy'. Note that the alternative name 'dunniken' is still with us in the form of 'dunny', which is an Australian slang term for lavatory.
There are older Dutch and German words 'krappe/krape' and an English version 'crappe' that could have been the source of Crapper's name, but none of these actually mean defecate or excrement.
Thomas Crapper didn't begin work as a sanitary engineer until 1861, several years after 'crapping' was clearly known as a slang term for defecating, so his name couldn't have been the source of the term. However, the coincidence of the name of the foremost Victorian sanitary engineer and the existing expression must have given an impetus to 'crap' being more widely taken up and hence staying with into the 21st century.