You are buying air sealing and insulation in one material, applied by trained crews with specialized rigs. Fiberglass is a material cost with simple labor. Foam is a chemical, equipment, and expertise cost, and it does a job batts cannot.
More detail
The price gap is real and it is not arbitrary. Three things drive it. Material. Spray foam is a two-component chemical system priced per board foot, and the components are petroleum-derived and volatile in cost. Fiberglass batts are a manufactured commodity sold by the roll. Equipment and labor. Foam requires a truck-mounted proportioner that heats and pressurizes both components to specification, hoses that stay heated to the gun, and a crew with the protective equipment and training to run it. That rig is a capital cost amortized across every job. Batts require a knife and a staple gun. What you get for it. Foam air seals and insulates in one application, and adheres to irregular surfaces where batts leave gaps. In a rim joist, a knee wall, or against a crawl wall, batts underperform their rated R-value badly because air moves around them. That is the case where foam is not the expensive option, it is the only one that works. Where it is worth paying. Rim joists, crawl space walls, unvented roof decks, knee walls, cantilevers, and any assembly where air sealing and insulation have to happen in the same plane. Where it usually is not. A big open, accessible, already-sealed attic floor, where blown cellulose or fiberglass reaches the Climate Zone 5A target of R-49 to R-60 at a fraction of the cost. Spending the foam budget on the attic plane, then blowing loose fill over it, is often the better allocation of the same money. Rough figures for this market: spray foam runs several times the installed cost of batts per square foot at equivalent R-value, and the honest comparison is not per R-value but per unit of actual performance in the specific assembly.