Long distance hikers obviously need to consume sufficient calories over the course of a trip to maintain body weight.
Strategies for doing so, of course, vary among hikers, but one approach that seems to be popular is to try to consume a base of about 2,000 calories a day eating fairly healthy, nutritious foods, and then to just pile on the calories with lots of fats and dense carbs thereafter until the daily target is met. Since it's not usually possible to carry that much food in one's pack, gorging in trail towns becomes an important part of the strategy.
Whether or not weight loss on any given trip can become potentially hazardous depends mostly on how much body fat any given hiker is carrying. It's my understanding that once body fat falls below 5 or 6 percent, the body's efficiency can suffer greatly.
Ryan Jordan of backpackinglight.com, when preparing for last year's Arctic 1000 trek made note in his blog about an earlier trip a few years earlier where he ran out of food in the Olympic mountains. His body fat dropped to 4.9% landing him in the hospital with renal failure.
On the other hand, Brian Robinson, over the course of his 7,400 mile triple-crown hike in 2001 apparently neither gained nor lost a single pound relative to his starting weight of 155, since his average calorie intake (about 6,000 calories a day) closely matched his expenditures.
By the way, a good resource regarding food for long distance hiking can be found here