الْحَمْدُ لِلَّهِ recognizes Allah's goodness, mercy, and favors. Supplication is not confined to requests for particular needs; praising Allah is also part of worship and the etiquette of turning to Him.
الْحَمْدُ is the subject of a nominal sentence. لِلَّهِ, a prepositional phrase, functions as its predicate: “Praise belongs to Allah.”
Saying “al-ḥamdu lillāh” after a blessing expresses gratitude. Saying it in difficulty sustains one's connection with Allah while still allowing prayers for relief.