It is no longer thought surprising or even scandalous that certain mental illnesses - notably hysteria, and, in our own time, perhaps, multiple personality disorder - seem to come and go. Therein lies their historical fascination, and Ian Hacking, philosopher turned historian of psychiatry, has trained his sights upon one that was born, flourished and disappeared remarkably rapidly: fugue (flight).

The first and paradigm case of this condition defined by fits of aimless wandering was Jean-Albert Dadas, a gas-fitter admitted to a Bordeaux hospital in 1886 in a state of exhaustion after foot-slogging across much of southern France, covering as much as 70 kilometres a day. His condition was investigated by a young physician, Philippe Tissié, who wrote it up in Les Aliénes Voyageurs . Dadas was soon on the road again, tramping all the way to Russia and Constantinople. Intense migraines and masturbatory binges would trigger his flight, and during his travels he was often intermittently amnesiac, though much of what happened would be brought back under hypnosis with Tissié.

A year later the great Charcot, that "Napoleon of the neuroses", came up with a case of his own (he claimed it had a pathological basis in epilepsy). Thereafter fugueurs proliferated, mainly in France, though German and Italian psychiatrists found it necessary, for chauvinistic reasons, to match the French, creating labels such as Wandertrieb and determinismo ambulatorio .

Fugue thus got on the map, but within 20 years the vogue had peaked. This was partly because its profile too readily fragmented, leading to different psychiatric schools getting involved in proprietorial dogfights - was it a branch of hysteria or epilepsy? Should it be treated with hypnosis or not? Like 18th-century Poland, fugue thus got partitioned and absorbed into other empires.

The rise and fall of fugue are handled by Hacking with a scintillating mix of intellectual energy, wit, bravura writing, pungent scepticism and deep erudition - he is a mine of information on everything from bicycling to boredom in Bordeaux. He does not buy the line that fugue was real, but he does accept that the diagnosis was "warranted" in its time. And he convincingly shows why it surfaced there and then by advancing a model of adaptation to an "ecological niche".

Four aspects were involved in the process, he argues. The first vector is "medical taxonomy". To become accepted, a condition needs to be challenging enough to stand out, but not so revolutionary as to smash existing thought frames. Ambulatory automatism fitted the bill. It did not require any threatening transformation of existing diagnostic terminology, yet it provoked debate as to whether it should primarily be associated with hysteria or with epilepsy.

The second parameter is "observability": to achieve recognition as an acknowledged form of mental illness a condition must be rendered visible as a disturbance. Thanks to its elaborate system of identity papers, the French bureaucracy made it simple to detect and detain people straying beyond their patch. Here lies one reason why the diagnosis never had a hope in the United States, where going West was quite the thing to do and utterly untraceable.

The third vector lies in what Hacking dubs "cultural polar-ity", the role of cultural preoccupations, in whose light a transient mental illness would acquire negative or positive evaluation. For fugue states in fin de siècle France these were, on the one hand, the "vagrancy scare" of the 1880s, and, on the other, the rise of romantic travel and mass tourism associated with Cook's tours, Baedeker guidebooks and the travel fantasies of Jules Verne and others. Thus Tissié would identify Dadas with the figure of the "wandering Jew", itself Janus-faced, both fascinating and feared.

The final element is "release", the ability of ambulatory automatism to offer an enticing escape route for persons of a certain class, time and place. Here "illness", as so often, promised gain. All the fugueurs were male, typically artisans or clerks, men with skills, households and a modicum of independence, but lacking the means for plush grand-tour travelling and too conformist for a life of crime or vagabondage. The runaway fugueur succeeded, at least temporarily, in escaping normal life without serious culpabilisation.

This "hospitable environment" hypothesis permits Hacking to be agnostic as to whether fugue was a "real" illness, while allowing him to regard its diagnosis as "warrantable". What might seem like equivocation derives in part from the fact that, though Dadas and other footloose fugueurs generated piles of paperwork, we actually have very little access to their innermost consciousness. This is frustrating, since it is impossible to determine just how far they truly succumbed to "irresistible impulses" to go walkabout, or rather staged their own AWOL episodes - Dadas never took off without first pocketing his identity papers and some cash.

At times Hacking writes as if he thinks that some mental illnesses are more real than others, in the sense of presenting more persistently over time. But his real interest lies in laying bare the mechanisms of adaptation to a niche, in particular, he insists, once Dadas had told Tissié his tale, they needed each other, as surely as Freud needed the Wolf Man or Charcot his star hysterics. Tissié was a pioneer cyclist, and Dadas, who always went on foot, started gyrating his legs in dreams as if pedalling. Tissié was fascinated by dreams, and so the compliant Dadas gave him dreams aplenty. Doctor and patient, Hacking notes, were "extremely accommodating to each other's needs and expectations" - a common psychiatric story, as earlier noted in his study of multiple personality.

What is beyond doubt is that the epoch had its own romance of travel, from Henri Murger's celebration of La Vie de Bohème to Baudelaire and Rimbaud. As frontiers closed and the modern state policed its subjects ever more closely, no wonder writers and poets dreamed of faraway parts and Dadas and his ilk actually hit the road. The psychiatrists who studied them were themselves not a little envious - as indeed, self-confessedly, is Hacking. Slip Mad Travellers into your backpack at once!

Roy Porter is professor in the social history of medicine, Wellcome Institute, London.