What compound forms when an atom of calcium gains two electrons from an atom of sulfur?
It is the other way around. The sulfur atom will gain 2 electrons from the calcium atom.
Metals lose electrons to nonmetals. So if sulfur gains 2 electrons from calcium, the calcium atom will become a calcium ion with a 2+ charge, and the sulfur atom will become a sulfide ion with a 2- charge.
The opposite charges will cause an electrostatic force of attraction between the oppositely charged ions, which will form the ionic compound calcium sulfide,