These two expressions are really quite similar, but there is a nuance of difference in the thoughts of the person who uses one or other of them - essentially, one expression is more empathetic than the other.
It's all about the context...
- Oh, I didn't get that dream job I was telling you about. I thought I'd done so well in the interview, but for some reason I wasn't picked.
- (Your friend says:) What a pity! It sounded just perfect for you. Anyway, never mind; have you got any other interviews coming up...
(Your friend thinks:) That's bad news for him, but it's not the end of the world...I guess something else will turn up eventually. There's no point in being miserable about that. Sometimes, you just need to move on to the next thing.
(Another (closer) friend says:)
- What a shame! You must be so disappointed. I know you were really hoping to get that one... Still you could always reapply in a few months time; there might be some openings for you then. You never know, it could be worth a try...
(This other friend is thinking:) I feel bad for my friend. I know how much he wanted to work in that organisation. I don't think he should give up hope completely.
Another example:
Did you hear the news about Queen Elizabeth husband Prince Philip dying?
('A' says:) What a pity - just a few more months and he could have celebrated his 100th birthday.
( 'B' says:) What a shame; he was just enjoying his retirement. And the Queen must feel so lonely too...