Sources
This hadith appears in many sources among them Sahih al-Bukhari with different versions or narrator chains. One of them goes through imam Malik who compiled it in his al-Muwatta' which also was the source of abu Dawod's and an-Nasa-i's version. Ibn Majah narrated with a chain that includes imam Sufyan a-Thawry and a slight difference in the wording. And imam Muslim narrated it through imam Sufyan ibn 'Uyyanah.
Translation
On sunnah.com in the two versions from imam al-Bukhari's Sahih the word:
الحياء
was not translated, but transliterated as:
Haya'.
While it is -compare other links from above- usually translated as:
Modesty or shyness
Definition
However الْحَيَاءَ may mean a lot more imam ibn Hajar quoted some longer definition in his Fath al-Bary فتح الباري . According to ar-Raghib al-Asfahany الراغب الأصفهاني:
In the following 'm translating from Arabic, as these translations are based on myy own interpretation take them with the necessary care!
I usually put additions to the original text or explanations into brackets
قال الراغب : الحياء انقباض النفس عن القبيح ، وهو من خصائص الإنسان ليرتدع عن ارتكاب كل ما يشتهي فلا يكون كالبهيمة .
Ar-Raghib said: al-Haya', is the retraction (of the inner self) from any thing that is detestable, and it is a specific attribute of humans, which prevent them from acting upon their desires (without limits) as an animal.
وهو مركب من جبن وعفة فلذلك لا يكون المستحي فاسقا ، وقلما يكون الشجاع مستحيا ، وقد يكون لمطلق الانقباض كما في بعض الصبيان . انتهى ملخصا . (Source)
And it contains fearfulness, chastity that's why a person acting upon haya' (Mustahyy) can't be lewd (Fassiq), and rarely a courageous person is meanwhile having haya' and it may apply for the retraction on the whole as it appears for some kids. End of summary of the quote!
He further noted the definition of other people saying:
وقال غيره : هو انقباض النفس خشية ارتكاب ما يكره ، أعم من أن يكون شرعيا أو عقليا أو عرفيا ، ومقابل الأول فاسق والثاني مجنون والثالث أبله . قال : وقوله - صلى الله عليه وسلم - " الحياء شعبة من الإيمان أي : أثر من آثار الإيمان ،
Others said: it is the retraction of the inner self due to the fear of performing something disliked, in general be it due to shar'ia rules, common sense or convention. And the opposite of the first is the Faasiq, of the second the insane and the third the dense.
And the saying of the prophet Allah's prayers and blessings be upon him: "haya' (modesty) is a branch of faith." means it is a sign or trace of faith (in a person).
وقال الحليمي : حقيقة الحياء خوف الذم بنسبة الشر إليه ،
Al-Halimy said: The reality of Haya' is the fear of the revile by trace back of evil to a person.
وقال غيره : إن كان في محرم فهو واجب ، وإن كان في مكروه فهو مندوب ، وإن كان في مباح فهو العرفي ، وهو المراد بقوله " الحياء لا يأتي إلا بخير " . ويجمع كل ذلك أن المباح إنما هو ما يقع على وفق الشرع إثباتا ونفيا
Others said: if it (Haya') was on something haram it is wajib, if it was on something frowned upon it is recommended, and if it was on something permissible it is according to conventions. And this is what is meant by his () words: " "Haya' (pious shyness from committing religeous indiscretions) does not bring anything except good."(Sahih al-Bukahri). And all this can be summarized in the statement that the permissible is all that happens in agreement of the shari'a either by affirmation or disproof.
See also on Arabic wikipedia some statements of scholars about haya' and also on the English page.
Meaning of the hadith statement
So the meaning of this hadith is that shyness, modesty or more generally haya' -as defined above- in a person is a sign that this person has faith in Allah and fears him and thinks twice before doing something Allah may have made haram.
So here the prophet () indirectly criticized the Ansari who in fact wanted to advise his "modest or shy" friend, by informing him that the attribute of haya' is a desired attribute for a faithful person.
And we know that it is among the attributes of the prophet () him self:
Messenger of Allah (ﷺ) was even shier than a virgin behind her veil. When he saw something which he disliked, we could perceive it on his face.
(Riadh as-Saliheen)