Yes, it works for melee spell attacks
A Melee Spell attack is still a melee attack. Melee attacks are melee attacks, but there can be different types (weapon, spell, etc.)
As long as it is a melee attack, then armor of agathys will trigger.
Yes, it will work for Spiritual weapon
This was actually more complicated than I thought it was going to be based on determining who is actually making the attack. While spiritual weapon is not a creature, and normally wouldn't trigger the armor of agathys, it is not the weapon that is delivering the attack.
Instead, the caster of spiritual weapon is the one actually delivering the spell attack. Spiritual weapon is (emphasis mine):
...a floating spectral weapon... When you cast the spell, you can make a melee spell attack against a creature within 5 feet of the weapon.
Had the language say it makes a melee spell attack, then armor of agathys wouldn't trigger as the attack isn't coming from a creature. But the language here is that you, a creature, are making the spell attack.
The spiritual weapon is basically allowing your character to make a melee attack against someone on your turn at a distance.