A variation of this actually happened to me in real life once. I had just moved to another state and one day went to purchase gas. As it does in the USA, you can use your bank ATM card as a credit card and thus avoid having to enter your ATM pin (the pump will ask for your ZIP to confirm it's you). I do this when possible to secure myself against skimmers.
In my case I had not actually forgotten the ZIP, I had merely forgotten whether I had yet informed my bank about my new ZIP. So I entered my old ZIP and of course it was wrong. Consequently the pump locked itself and displayed a message telling me to see the attendant.
Lazy as I am, I decided to wait for a minute to see if the pump would unlock itself so that I could try again with my new ZIP (it did not). In the end I just had to walk to the cashier and my little issue was resolved.
Now of course the station that I was on actually had a cashier inside. It was also not a particularly small station, which means that I might have been able to solve my issue by trying my card at the next available pump. (On the other hand the OP mentions "a stranger at another pump" but it's not clear if in his case the station only had that one other pump).
Since you do not seem to question the mans claim that there was "nobody to accept his cash" it seems unlikely that there was any other option than paying for his gas with your own card.
(Here in America I have also not seen those pumps they have in Europe where people can pay by inserting cash.)
That being said, it's not dangerous in itself to pay in behalf of a stranger, although sometimes questions like these can be a pretext to get you to take out your wallet or to use your card at a machine equipped with a skimmer.
Probably more likely though he was in need of some monetary assistance and buying him gas for $5 (currently this gives at least 2 gallons / 8 liters of "regular" in most states) would have been sufficient.