In the context of large supermarkets, the cost of coffee is almost always directly correlated with the degree of marketing foo on the label. You pay extra for certifications and the terms that come with them: fair trade, shade grown, organic, etc. As we've said time and again, these terms are not generally correlated with quality.
In a cafe setting, the cost of prepared coffee is all about labor. When measured in terms of their cost per pound, Espresso drinks top out at over $50 per pound. Here, customers pay for the convenience of preparation, the cost of other ingredients like milk, the ubiquity of access, and the time-metered use of a costly espresso machine (and the training required to operate it).
In smaller cafes, and among small-batch roasters, higher prices are all about the bean and its quality, and that cost is a function of paying smaller farmers for micro lots of green coffee (i.e. pre roasted). Competition for higher quality beans is becoming ever stiffer, and the scarcity of great crops will only grow over time based on worldwide agricultural struggles with weather, climate, predation, and disease.