It’s said that in one of Imam Ali’s battles with one of the disbelievers, the disbeliever asked Imam Ali for his sword as a gift and Imam Ali threw his sword towards him. Which battle was it, why did Imam do that and how did the disbeliever respond?

It was in the battle of Siffeen.
That shows Imam Ali is an epitome of Justice and guidance. He did that to guide the gentle.
The man eventually joined the camp of Imam Ali