This is essentially down to Revenue Management - "how can we make the most money from this flight?"
TL;DR: It saves you money in the long run, and is about filling the plane, not charging everyone the same price per mile
Airlines regularly provide different prices for routes, parts of routes, different countries of purchase etc. They'll charge you more/less based on the class you fly, how early/late you book, how flexible you are, where you live, where you purchase the ticket, where you're flying to/from.
For example if you're buying a ticket from the UK, you're likely to pay more for a Heathrow->Jakarta flight than someone from Jakarta is - the airline know you likely have more money and higher expectations of cost, so they'll charge you more.
It's not about "here's how much the plane costs to run, it holds 200 passengers, so divide that by 200 and that's the price of a ticket", it's about "how much money can we make?"
It's the same reason that ticket prices will be low a year before the flight (to encourage early bookings/cover the basic costs/get some cash flow), then will go up a couple of months before the flight (when most people are buying) and drop as it gets close to the flight date and the airline just wants to get the plane full.
Note that you won't always find it's cheaper to buy the separate tickets, and in many cases it's more expensive - it's just that the airline has found (or predicted) that they'll make more money that way. This seems counter-intuitive when we compare it to most other purchases, where the price is set at (cost to make + profit margin) and is fairly fixed, but it's pretty standard in the Airline industry.
In cases like the one you mentioned the chances are that the total route makes good money, but the airline knows that the plane won't be full. They also know that people won't pay full price for the "segments" of the journey (perhaps they have competition from low-cost carriers) but they want to fill the plane up. They can't afford to offer everyone the lower price (or they'd lose money on the flight), but they can sell some of the "one segment" tickets for above-cost and therefore make some profit, or covers some of their fixed costs.
To run a plane there are fixed costs (pilot wage, airport fees) and variable costs (fuel) - the segment costs are paying for the extra fuel to carry that person and their baggage, plus a little extra towards the pilot's wages, so it's still making that journey cheaper for you than if the seat was empty and you had to pay the whole pilot's wages.
It seems unfair, but it's actually making your journey cheaper - the airline would have to charge the full-journey passengers more if there were empty seats.
Think of it this way, I have a two seater sports car and want to drive from Paris to Moscow, via Munich. It's going to cost me €200 in fuel, maintenance etc. I want to make my car cheaper than the train. I decide to pick up a hitch-hiker for a fee, to get my costs down to half
I try to find someone to split the costs with me (€100 each), but nobody else wants to go to munich (I can't fill my car/plane). I know someone who wants to go Paris-Munich, and someone else who wants to go Munich->Moscow, but neither of them want to pay €50 for half of the journey (the local markets don't support the same cost) so I decide to charge them €40 each
I charge them €40 each, meaning I get a total contribution of €80 towards the €200 - and I'm still paying €120. "But that's not fair!" I cry, "They're not paying as much!". It's at this point I realise that although they're getting a better deal than I am, I'm still only paying €120 instead of €200... if I tried to charge them €50 each, they just wouldn't have come along and I'd be left with the full cost.
Airlines have to work in the same way - offering the best price to as many people as possible to match market conditions and fill the plane to cover the costs. Sometimes, that feels unfair - but without the unfairness, it would cost everyone more.
Source: I've spent the last few years working in Airline Revenue Integrity