Same as everything else, supply and demand.
The most important variable is competition. Until airline deregulation in the late 1970s, rates for flights were more-or-less determined by distance. Now, ticket prices have almost nothing to do with how far you’re traveling and more to do with how many airlines are competing for your business.
An airline will adjust its ticket prices on a minute-by-minute basis, depending on what competitors are charging. But how do they know the other guys’ prices? Each airline enters its rates into the Airline Tariff Publishing Co. computer system, which in turn supplies information about all the others.