It seems obvious -- but I guess it isn't.
The gas station owner buys a tanker full of gasoline. At that point the gas is his. He owns it. It belongs to him -- just as surely as you own your house or that your car belongs to you.
He can try and sell it for $5.00/gallon (and not sell very much if any) or he can choose to shut down the pumps and just use his little hoard of gas to fill his own car (and not let us have any of it).
The gas station owner wants to maximize his profit and so he sells that gasoline at the highest price he can that doesn't hurt his sales. When the wholesale price is rising, of course he will raise his prices as fast as he can and as fast as his competition will allow.
And yes, his profit on the gas already purchased will go up. He is thinking ahead, of course. If the prospect is likely that wholesale prices will continue to rise then he will want to bank as much as he can to pay for higher replacement costs.
When the wholesale price is dropping -- guess what -- he will want to continue selling at the higher prices for as long as he can. And why wouldn't he? He's trying to make a living.
Eventually, other stations in the area will begin to drop their prices and he will have to follow suit if he wishes to maintain his customer base.
None of this is any different than trying to get the highest price you can when you trade in a car or when you sell your house.
This thread smacks of "capitalism for me but not for thee".