These are two distinct hadith that Imam al-Nawawi has put together under the title, "Hadith Number 27". Probably, it is due to the closeness of their subject matters that led him to do this.
A few lessons we can take from these beautiful ahadith are as follows:
Before a believer performs any act that is not clearly righteous or sinful, he should look to his heart and see what he feels about that act. If our hearts feel fine with it, we should do it. If our hearts are uncomfortable with it, we should leave it.
If a person is a TRUE believer (who always seeks to prioritise the pleasure of ALLAH over their desires) and is indifferent between having people see him/her perform an act or having it kept hidden from them, this is a sign that the act must be a righteous act or a permissible act.
Islam provides a strong, living internal factor that controls the behavior of believers. The question for a believer is not simply whether he can get away with an act or if there is nothing in the secular law, for example, that prohibits that act. He/she, instead, stands in front of the "higher authority" who knows what is in his heart. He will not perform an act, even if he could easily get away with it, if inside he does not feel it is righteous.
To learn more, do check out Commentary on the Forty Hadith of Imam An-Nawawi by Sheikh Jamal Al-Din Zarabozo, vol. 2, page 829.