All perfect praise be to Allaah, The Lord of the worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and messenger.
According to the basic rule, performing Hajj and ‘Umrah is better than voluntary charity because they involve spending money as well as other righteous deeds such as Tawaaf, Sa‘y, Thikr, prayer, Talbiyah and so on. However, if a person finds some people who are in need of his financial support or has needy relatives and he cannot afford to combine giving them charity and offering (a voluntary) Hajj, then giving charity is better in such a case.
Al-Hattaab, the Maaliki scholar said: "Maalik was asked which was better in his sight; performing (a voluntary) Hajj or giving charity? He said that performing Hajj was better unless it was a year of famine."
Shaykh Al-Islam Ibn Taymiyyah said: "…however, if he has needy relatives, giving them charity is better than (a voluntary Hajj) and the same applies if there are poor people who are in need of his financial support. If both actions are to be done voluntarily, then performing Hajj is better because it is an act of worship that combines physical and financial aspects. Likewise, offering an Udh-hiyah and ‘Aqeeqah is better than giving out their value as charity."
Having known this, you should also know that the attitude of ‘Abdullaah ibn Al-Mubaarak in the incident you referred to is as follows: "Once, Ibn Al-Mubaarak set out for Hajj. While he was passing through a village, a bird that they had with them died so, ‘Abdullaah ibn Al-Mubaarak ordered his companions to place it on a rubbish dump. When his fellow travelers proceeded forward and he was behind them, he noticed a girl who came out from a nearby house and ran to the rubbish dump. She took the dead bird, wrapped it and hastened to her home. ‘Abdullaah ibn Al-Mubaarak followed her and asked her why she had taken it. She told him that she and her brother had nothing other than this loincloth and no food to eat but what is thrown in this rubbish dump. Eating dead animals became permissible for us days ago. Our father had money but was robbed of all his money and killed." Upon hearing this, ‘Abdullaah ibn Al-Mubaarak asked the caravan to give him back the luggage to whomever it belonged and asked his trustee who held the money: “How much money do you have?” The trustee said: “One thousand dinars”. ‘Abdullaah ibn Al-Mubaarak said: “Take twenty dinars that would suffice us in our return journey to Marwa (i.e. his home town) and give her the remaining amount. This would be better than our Hajj for this year.” Then, he returned to his homeland.