Oops. I see a typo in my previous comment. The third paragraph should say "... you still OWE the gallery a commission." In other words, send them a check.
A related topic is a referral from a gallery. That is when the client likes what they see in the gallery but want to see more of your work and the gallery gives them your contact information. If they buy a different painting, the gallery is entitled to a referral fee for that sale - which is often 1/3 to 1/2 of what a full commission would have been if the gallery sold it.
This gets a little tricky because they might have found your contact info on the internet or picked up your business card somewhere else, so unless the gallery calls and says "I just gave your contact info to Sam Slade and he would like to stop by your studio to look at some more paintings," you don't know whether it's actually a referral.
Whether it's a referral or an after-the-show sale, the basic question is: "Did the gallery put forth some effort that resulted in the client making a purchase?" If so, it is fair to compensate them for the effort.
Today many artists choose to bypass galleries altogether and just sell via the internet. There's nothing wrong with that. The artist takes on the marketing and sales responsibilities that a gallery traditionally has done, so the artist gets the money that would traditionally have gone to the gallery commission.
But for those of us who also rely on gallery shows for part of our income, it is important to remember that they have costs like rent, staff salaries, advertising, etc. that must be paid from commissions. If we undercut them by selling our work cheaper behind their backs, they won't be in business to promote and sell our work.
If you treat your galleries in a professional manner, they are likely to treat you fairly too.