Full disclosure: I'm going to sound like a Republican married to Exxon in the following. I'm not, but I just finished nearly 16 years dealing with gas stations for an environmental agency. Now that I've moved on, this post has awakened some nostalgia and I've written too much.
Gasoline is a commodity and commodity prices vary. Go down to Agway to buy 50 lbs of animal feed and or over to the fish restaurant for a lobster dinner and today's price might not be yesterday's. CT has laws prohibiting a gas station from raising its prices on previously delivered fuel, but most stations get deliveries at least every few days, making it easy to blame any increase on a new delivery. So the prices can rise quickly.
By the way, of course gas prices are higher in a wealthy area. Gas station properties down in CT's wealthy Republican strongholds sell for millions of $ more than similar properties here. Those wealthy towns also impose all kinds of restrictions on hours of operation, site upgrades and so on that limit their sales. Higher costs divided into lower sales = higher prices. If the people will pay those prices, the gas stations remain gas stations. Otherwise, they'll become something else. As Rattler said, they do make a lot off of junk food sales.
Prices aren't only high in wealthy areas, by the way. They're high in poorer communities too, whether in a ghetto or out in the middle of nowhere, because much less gas gets sold and that cost/sales equation strikes again. Sprawling suburbs seem to have the lowest prices, since there's enough income to support plenty of business, people are driving every which way, boosting sales volumes, and towns are desperate for whatever commercial development they can get, so they make it easy for gas stations do whatever they want to increase their customer base.
Gas stations usually have at least a couple tanks and most around here have something in the range of 15,000 - 30,000 gallons of total storage. Gasoline prices being what they are, most of those tanks aren't being filled all the way. Even at the lower wholesale prices, there can be $100,000 in the ground. Most of those big suburban stations are selling 1,500,000 gallons or more per year, so a lot of money passes through their hands and they can make a good income on a pretty small margin. With rapidly rising prices, that business model can fall apart, since the gas station have to pay more to fill the tanks today than they put in the register while emptying them yesterday. It can become a serious cash flow problem and, as Rattler also said, places can go out of business. They keep ordering less and less gas and, eventually, they don't order any at all.
Gas stations are the market at work in the real world. The powerful game the system, the weak lose their shirts, a resource is wasted, there's plenty of pollution and those getting the benefits don't pay all the costs. It's all of capitalism's advantages and flaws in plain sight.