The names of the surahs are not part of the actual text of the Qur’an, nor were they written in the early mushafs. For some (but not all) surahs there are explicit narrations telling us that the Prophet (may Allah bless him and grant him peace) himself used a particular name. And the narrations suggest that all the names were well-known and widely used among the Sahabah. `Allamah al-Suyuti has stated that the names of all the surahs can be found in either hadiths or aathaar (sayings of the Companions). Among these is the narration that the polytheists used to make fun of the fact that there are surahs named after the cow, the spider, etc, whereupon Allah sent down the verse meaning, “We are sufficed for you against the mockers.” [Qur’an, 15:95]
However, the scholars disagreed as to whether the name of every surah was given by the Prophet (may Allah bless him and grant him peace) himself. It is quite possible that some of the names were assigned by the Sahabah. Al-Suyuti also mentions that some surahs are known by more than one name, and similarly sometimes the same name may be used to refer to more than one surah.
And Allah knows best.
[The above information is drawn mainly from Jalal al-Din al-Suyuti’s Al-Itqan fi `Ulum al-Qur’an]