A lunatic (colloquially, "loony") is a person who is mentally ill, traditionally someone whose sanity comes and goes with the phases of the Moon.
This probably refers to the symptoms of what is now known as Bipolar disorder.
Extremely foolish persons are also called lunatics.