Both sentences can be called commiserations, a noun that means “The act of commiserating; sorrow for the wants, afflictions, or distresses of another; pity; compassion”, or may be described as sentences.
Besides being commiserating, as suggested earlier the sentence “I'm sorry for your loss” is indeed a condolence, or “An expression of comfort, support, or sympathy offered to the family and friends of somebody who has died”.
While “I'm sorry you couldn't figure that out” may express empathy, whether it actually does so depends on text and tone of voice. It is empathetic if the speaker understands and sympathizes with the listener. It is regrets (expresses a feeling of sorrow) if the speaker is sorry that the listener didn't figure something out; for example, if a test-taker does badly on several questions, a teacher might be sorry but not sympathetic or empathetic. It may be sarcasm if the speaker thinks the problem is trivial or obvious and could have been figured out easily.