Mmmm... evolution.
There's a whole field of animal behaviour that looks at energy budgets (this might not be the correct term, by the way, I'm just vaguely recalling something I've read).
The idea is that an animal will only have so much energy and it obviously needs to prioritise the survival of its young. So there are different strategies available, and animals will tend to use the one which is most energy-efficient: wasteful organisms don't survive.
So, for example, a duck might hatch 10 ducklings but have only 2 survive to adulthood. That seems wasteful but it's OK because the duck doesn't really invest all that much energy into raising and feeding ducklings, it's all a bit sink-or-swim in the duck world.
But primates (both human and non-human) have a strategy which is very different: they have far fewer offspring but invest a HUGE amount of energy into raising them and keeping them safe. Does it work? Yes, clearly, it's been working for millions of years and the most intelligent primate is one of the most successful organisms on the planet.
Sooooo..... finally welliemum approaches the point....
If we humans have the biological ability to breastfeed a 7 year old child, you can bet your bottom dollar there's a survival advantage to doing so, ie it's beneficial to either mother or child or both. If not, the waste of energy would have phased it out long ago.
I would guess that the survival advantage in bf a 7 year old in today's society is small. But the simple fact that it can be done implies very strongly that it's been beneficial in the past, and who knows - it could still be beneficial, but our society has made it nearly impossible ever to answer that question.
(I promise I didn't make this all up in the bath, but I'm no expert on this stuff - am hoping for a biologist to swing by and add some actual knowledge to my vague notions)