There are elements of truth in most of the other answers, but as a 16-year veteran of the rental car industry in the US, I'll toss my take into the mix.
Most of the time when you're searching, the answer is: "because they can."
What I mean by that is that the whole "well, someone has to drive it back to the renting office" is not actually the case. That's because most rental offices in mid-size and larger cities are corporate-owned, and all three of the big-name rental companies that operate the eight major brands (Avis, Budget, Enterprise, Alamo, National, Hertz, Dollar, and Thrifty) now use a "floating fleet" model, which means that the companies maintain a nationwide single fleet and any car can be assigned to and rented from any location at any time.
So if someone rents a car at Avis LAX and returns it at Avis in Austin, the car simply gets washed by the detailing crew at Avis Austin, placed in a parking stall at Avis Austin, and assigned to the next Avis Austin customer who comes in to pick up that size car. The same thing happens if they rent at Avis LAX and return at Avis in downtown Los Angeles or Avis in Midtown Manhattan or Avis at Chicago Midway airport. That's why a large number of license plates on any corporate-owned rental lot tend to be from out of state.
Now, of course, for every person who picks up in LAX and returns elsewhere, there's usually someone renting elsewhere and returning in LAX, so the fleet tends to stay pretty balanced. That's why I say they charge the one-way fee "because they can"--because there really isn't a hard cost to them. Cars go out, cars come in, and all is good. But the market (supply, demand, and competition) allows them to charge a premium price for one-way rentals, so even though there's no (or a very minimal) direct expense associated with these kinds of one-way rentals, they do it because they can.
Of course, sometimes one-way flows do result in an imbalanced fleet. If LAX loses too many cars and they have fewer cars than they forecast needing to meet demand, then they do have to arrange for cars to be brought back from somewhere else. So sometimes it is necessary to truck a load or ten of cars in from elsewhere, and that does have a cost, so collecting one-way fees allows them to cover those costs.
It's worth mentioning that seasonal demand can have some interesting effects. I've taken advantage of the fall "Florida Drive-In" specials, where picking a car up in the Northeast and dropping it off in Florida can net some extremely attractive rates ($5-10 per day or so)--cheaper than a standard round-trip rental! This helps the rental car companies move cars from the colder northern states (where demand slacks off in the winter) to the warmer southern states (where winter is peak season). It's much cheaper to have people drive cars down for you than to pay a car carrier to haul it down by truck or, even worse, to have cars sit idle in the north while offices in the south buy or lease extra cars to meet demand. (There's also the related Florida Drive-Out special that takes place in the spring and some less-lucrative similar offerings out west.) So it's not always true that one-way rentals are more expensive!
As well, there are certain places where one-way fees seem to be very reasonable or even not charged. One answer mentioned rentals in Germany--that's a place where one-way fees seem not to be part of the local rental culture, unless you try to drop the car off outside of Germany. Intra-Florida rentals are often quite cheap (due to a ton of competition--it's the largest rental car market in the world and there are literally dozens of rental car companies that operate at Florida's major airports), and intra-California one-ways are frequently not charged fees, too (that's because the one-way flows between places like Los Angeles and San Francisco are pretty balanced--as many people are interested in driving up Highway 1 as are interested in driving down Highway 1, I suppose), so that, combined with the high volume and competition, lends itself to reasonably-priced one-way rentals.
Now, when it comes to franchised locations, one-way fees are based much more in the realities of rental car logistics. If a car owned by a licensee location (typically found at smaller, more rural airports or in some smaller towns) ends up far away from its base, there are hard costs to deal with that situation. The best option is for the receiving location to rent the car back to its owning location on a paid one-way rental, but there's no guarantee of that happening quickly, and the owning location loses the potential revenue of the car they paid for until it gets back into the fleet. Failing that, the owning location has to pay to have the car transported back home, either by car carrier or by sending an employee to go retrieve the car--not a small cost. And in a worst case situation, the least-bad solution is for the owning location to simply sell the car to the receiving location, but that's obviously not without its own costs and logistical headaches.
In these cases with franchised locations, the one-way fees are actually intended to be punitive and dissuade people from choosing that option, but they also cover the rental agency's costs if someone does require a one-way rental.
I should also address a couple of topics with one-way fees. Most rental car agencies now don't quote an explicit, broken-out one-way drop fee, instead baking the one-way fee into the rate itself. For example, a standard round-trip rental in Portland might run you $40 per day, but if you quote a reservation for a one-way to Seattle, it might balloon up to $100 per day. However, some companies, as well as some booking channels (usually prepaid brokers), still break the fee out (for the hypothetical Portland rental, both the round-trip and one-way rentals would price out at $40 per day, but the one-way would have a $100 drop fee attached).
The former model works best for short rentals, while the latter is more advantageous for longer rentals. In the Portland example, if you can do your one-way drive in a single day, the included one-way is cheaper (a net extra charge of $60). But if you're going to take a week to drive the Washington coastline, the weekly rate would balloon from a couple hundred bucks to north of $500. With a separately-itemized $100 drop fee, you'd pay the same fee even if you kept the car for a month. In any case, the best thing to do is just plug your dates and locations into a search engine that searches all rental companies at once and choose the one that displays the cheapest total price (ignore the base rate and pay attention instead to the total with all taxes and fees).
Mileage fees are sometimes charged, but they're more common with franchises. However, sometimes you'll see them applied at major locations depending on what kind of discount code you use. For example, the USAA discount code with Hertz returns very attractive rates even on long-distance one-ways until you notice the catch: an almost punitive mileage fee that can total hundreds of dollars. Unless you're literally just driving across town, mileage-based one-way fees are rarely the best option.