Why would SAN-ORD have a BA code but not SFO-ORD or LAX-ORD?
Because the BA code on domestic AA hops is traditionally used when connecting to a BA transatlantic (to LHR). SFO and LAX originating pax can get onto BA metal nonstop to LHR and do not need to fly to ORD to get to LHR, while SAN originating pax do need the feeder flight on a BA partner carrier.