A lunatic is a person who is mentally ill or behaves in an extremely foolish manner. Demented is a synonym that describes someone suffering from cognitive decline or acting irrationally. The other options like stupor or derail do not share this meaning.