I believe the best way to understand pricing is to understand what the ultimate goal of the airline is, which is to fill as many seats on each plane as possible with people paying as much as possible.
Like most any product or service, different people place a different value on the same service. For instance, I may be willing to pay $1000 to fly from Dallas to New York to attend a business meeting, while my mother may only be willing to pay $300 for the same flights to see a broadway show. Airline pricing recognizes this fact and is an attempt to ensure that the price each passenger pays comes as close as possible to the maximum price they would be willing to pay for the trip. That is why low fare tickets have restrictions that make them unsuitable for business travelers who are willing to pay more.
There are various contraints on the range of fares that are offered -- primarily being competition and supply/demand. On routes with an excess of seats (such as transatlantic during recent winters) you can see restricted fares drop to extremely low leves as airlines try to fill seats on the planes. Since many passengers will switch to an airline when a fare is lower, airlines often have to match fares introduced by their competitors (who may have a different opinion of what fare will fill all of the seats or may not be acting so as to maximize revenue in order to achieve some other goal, such as bleeding a competitor to death).
Over the years, airlines have developed advanced computer systems which use historical data to predict what the demand for various fares will be on a particular flight at a particular time. Based on this, they will decide how many seats to offer at different fare levels.
So back to your question on why it is cheaper to fly from BWI to SFO via PHL than from PHL to SFO on the same flights, the best explanation is that people are willing to pay more to fly from PHL to SFO than from BWI to SFO. Of course, the fare at any particular time on any particular flight is subject to the influence of competition, demand, etc. The fact that the flights are the same is really immaterial, since the airline is selling you travel from one point to another (Delta wouldn't charge you more for connecting in ATL than CVG even if ATL is a couple hundred miles further).
Bottom line -- No one ever paid more for an air ticket than the trip was worth to them and the goal of the airlines is to ensure that no one ever pays less than the trip is worth to them.