I know a woman should take her guardian's will for marriage before proposing to marry someone and if her guardian refuses her right to marry then his guardianship becomes void and that she can choose someone else from her relatives preferably on her father side to act as her guardian, such as uncle, grandfather, mother or brother. Above all else, it is required for her first wedding to have a Guardian's permission as mentioned the the following hadiths.
“There is no marriage except with a walee” and “Any woman who gets married without the knowledge of her walee, her marriage is invalid.”
However, there is another hadith in Sahih Al-Bukhari which states
Sahih Al-Bukhari Volume 6, Book 61, Number 547Number 547 : Narrated by Sahl bin Sad A lady came to the Prophet and declared that she had decided to offer herself to Allah and His Apostle. The Prophet said, "I am not in need of women." A man said (to the Prophet) "Please marry her to me." The Prophet said (to him), "Give her a garment." The man said, "I cannot afford it." The Prophet said, "Give her anything, even if it were an iron ring." The man apologized again. The Prophet then asked him, "What do you know by heart of the Qur'an?" He replied, "I know such-and-such portion of the Qur'an (by heart)." The Prophet said, "Then I marry her to you for that much of the Qur'an which you know by heart."
This hadith is mentioned at several other places as well and something seems fundamentally wrong here. The prophet SAW didn't care to ask her about her guardian's consent, instead he married her right away, acting as both a Qazi and a Wali. I know a Qazi can act as a wali in circumstances where a rightful wali is absent, but isn't it a duty of a Qazi to inquire if there is a Wali present or not? These hadith seem to be contradicting each other.
Question: Are these two ahadith in Bukhari about guardian marriage contradicting each other?
If not, explain why they aren't!