Goya painted the Spanish royal family, including Charles IV of Spain and Ferdinand VII. His themes range from merry festivals for tapestry, draft cartoons, to scenes of war, fighting and corpses. This evolution reflects the darkening of his temper. Modern physicians suspect that the lead in his pigments poisoned him and caused his deafness since 1792. Near the end of his life, he became reclusive and produced frightening and obscure paintings of insanity, madness, and fantasy. The style of these Black Paintings prefigure the expressionist movement. He often painted himself into the foreground.
In a period of convalescence during 1793-94, he completed a set of 11 small pictures painted on tin, called the pictures of “Fantasy and Invention” that mark a change in his art. These paintings no longer represent the world of popular carnival, but rather a dark, dramatic realm of fantasy and nightmare. "Courtyard with Lunatics" is a horrifying and imaginary vision of loneliness, fear and social alienation, a departure from the rather more superficial treatment of mental illness in the works of earlier artists such as Hogarth. In this painting, the ground, sealed by masonry blocks and iron gate, is occupied by patients and a single warden. The patients are variously staring, sitting, posturing, wrestling, grimacing or disciplining themselves. The top of the picture vanishes with sunlight, emphasizing the nightmarish scene below.
This picture can be read as an indictment of the widespread punitive treatment of the insane, who were confined with criminals, put in iron manacles, and subjected to physical punishment. And this intention is to be taken into consideration since one of the essential goals of the enlightenment was to reform the prisons and asylums, a subject common in the writings of Voltaire and others.
This condemnation of brutality towards prisoners (whether they were criminals or insane) was the subject of many of Goya’s later paintings.
As he completed this painting, Goya was himself undergoing a physical and mental breakdown. It was a few weeks after the French declaration of war on Spain, and Goya’s illness was developing. A contemporary reported, “the noises in his heads and deafness aren’t improving, yet his vision is much better and he is back in control of his balance.” His symptoms may indicate a prolonged viral encephalitis or possibly a series of miniature strokes resulting from high blood pressure and affecting hearing and balance centers in the brain.
In 1799 he created a series of 80 prints titled Los Caprichos depicting what he called "the innumerable foibles and follies to be found in any civilized society, and from the common prejudices and deceitful practices which custom, ignorance, or self-interest have made usual."
In The Third of May, 1808: The Execution of the Defenders of Madrid, Goya attempted to "perpetuate by the means of his brush the most notable and heroic actions of our glorious insurrection against the Tyrant of Europe" The painting does not show an incident that Goya witnessed; rather it was meant as more abstract commentary.
In later life Goya bought a house (Quinta del Sordo - the Deaf Man's House) and painted many unusual paintings on canvas and on the walls, including references to witchcraft and war. One of these is the famous work Saturn Devouring His Sons, which displays a Greco-Roman mythological scene of the god Saturn consuming a child, a reference to Spain's ongoing civil conflicts. This painting is one of 14 in a series called the Black Paintings. After his death the wall paintings were transferred to canvas and remain some of the best examples of the later period of Goya's life when, deafened and driven half-mad by what was probably an encephalitis of some kind, decided to free himself from painterly strictures of the time and paint whatever nightmarish visions came to him. Many of these works are in the Prado museum in Madrid.
In the 1810s Goya created a set of aquatint prints titled Los Desatres de la Guerra (The Disasters of War) which depict scenes from the Peninsular War. The prints were published in 1863, 35 years after his death.