My view is that it's inappropriate to jump in front of customer B, for a couple of reasons.
First, it's likely that customer B's order is going to be complete before I'm done paying at the cashier. So my jumping in line is going to directly delay customer B, which I think is wrong because customer B was clearly there first.
Second, it's possible that one of customers C, D, and E might be in a similar position, where they are only interested in buying a gift card. Again, it would be clearly wrong to jump in front of someone similarly situated.
The counterargument is obviously that this is similar to ordering online from a place like Chipotle, where you bypass the burrito-making area and head directly to the cashier. I am fine with that process, and I think the difference is that there's an established protocol in place, where all Chipotle customers collectively understand how online ordering works. It says so right on their website:
What's crazy is that my wife, I think, inadvertently proved my point for me, because this particular ice cream shop was not the first place we went. (We were buying gift cards for our kids' swim team coaches fwiw.) We first went to a different ice cream shop, where my wife saw a HUGE line stretching outside of the building. Upon seeing said line, she said, "Oh we're definitely not going there." And that's when we went to the above-illustrated shop, where there was a line of only about 4 people.
But, as I realized when we were driving home, if she REALLY believed her own argument - that you can just jump directly to the cashier and bypass the ice cream line - then it wouldn't have mattered how long the line was at the first place because we wouldn't have waited in it. I was like, "BOOM, LAWYERED". But she remained unconvinced.