I can't speak for the literary developments but almost certainly the work that popularised, if not created, the mad scientist trope was Mary Shelley's Frankenstein (1818).
The 20th Century development of the trope began in movies in the silent era. There was the scientist Rotwang in Metropolis (1927), although there are earlier examples than this.
However the work that popularised the trope was Frankenstein (1931) starring Boris Karloff. This spawned a great many copycat mad scientist films throughout the 1930s and 40s. This very much reflected a view of science held by the public of the day, coming several years after the Scopes Monkey Trial where the teaching of evolution was challenged in the courtroom and science seen as something dangerous by the uneducated. Frankenstein was naturally followed by a whole heap of films where scientists ventured into areas of divine provenance - raising the dead, trying to create immortality, transplanting brains into apes, and even heart-transplants! Such scientists did their science in Gothic surroundings such as castles and amid lightning storms and it was seen that the natural effect of this was madness or their being killed by the process. The process was always doomed to failure and going amok.
The mad scientist genre had largely died away by the 1950s, although there have been a regular stream of stragglers. By the 1950s, the scientist had become much more friendly and the hero who saved the day or built rocketships in a number of the alien invader films of the 1960s and was usually a family man or often engaged in a romance. Or else they were eccentric characters as popularised by Disney's The Absent-Minded Professor (1961). In the real world, of course the perception of scientists had changed and they were the heroes at the forefront of Space Race.