How did Bhishma Pitamaha know the Vishnu Sahasranama? Who gave it to him?
The thousand names of Vishnu said by Bhishma Pitamaha were far famed and already sung by Rishis and other great people. Hence, he knew them already. Those names are famous because they are already found in the works of Rishis.
yāni nāmāni gauṇāni vikhyātāni mahātmanaḥ|
ṛṣibhiḥ parigītāni tāni vakṣyāmi bhūtayē ||
I am giving for the benefit of all, those names of His which are far-famed, which are indicative of His attributes, and which find a place in the exalted hymns of the ṛṣis.
The above verse is from the conversation of Bhishma and Yudhishtira itself.
Bhishma Pitamaha was a Gyani. He learnt Vedas, dharma shastras and other literature from great rishis like Shukracharya, Brihaspati, Vashishta. In Padma Purana, we will also find his conversations with sages like Pulastya also.
In Adi Parva, Sambhava Parva chapter 100 of Mahabharata, when Ganga Devi introduces Bhishma to Santanu, says
And go home, O tiger among men, taking him with thee. Endued with superior intelligence, he has studied with Vasishtha the entire Vedas with their branches. Skilled in all weapons and a mighty bowman, he is like Indra in battle. And, O Bharata, both the gods and the Asuras look upon him with favour. Whatever branches of knowledge are known to Usanas, this one knoweth completely. And so is he the master of all those Sastras that the son of Angiras (Vrihaspati) adored by the gods and the Asuras, knoweth. And all the weapons known to the powerful and invincible Rama, the son of Jamadagni are known to this thy illustrious son of mighty arms. O king of superior courage, take this thy own heroic child given unto thee by me. He is a mighty bowman and conversant with the interpretation of all treatises on the duties of a king.'
Due to his enormous knowledge of Dharma, he instructs Yudhishtira the raja dharma and other dharmas. Due to his teachings, Yudhishtira was free from sorrow of the war. So, it is not surprising that he knew the names from the rishis' hymns.