When you use your credit card either in the store to pay for gasoline or when you use your credit card to pay for the fuel at the fuel pump the reason they ask for your zip code is for fraud prevention.
It's a security measure so that you know your zip code and helps to prove you own the credit card you're using for the fuel purchase.
Sometimes the zip codes are also used for marketing purposes but mainly it's a fraud prevention measure.