Both sentences are grammatical—although the first is far more common. It depends on what you are trying to express.
I am a friend of his.
This means that I am his friend. We hang out together, talk, and are sociable. This is almost always what people mean.
Grammatically, the possessive pronoun his is used because you are saying you are the object of his friendship.
I am a friend of him.
This is a much less common phrase, and can also be expressed as I am a friend to him.
It may not mean that you have ever spoken to him. (Although often you will have.) You feel goodwill toward him and most likely have done things that have helped him. It is more figurative than literal.
Variations of this non-possessive sense would be:
I am a friend of nature. [But nature is, obviously, unaware of this.]
I am a believer in him. [Him the object, without any possession.]
So, let's take your first example sentence:
A friend of him had given him the bad news.
Perhaps it was somebody he had never met, but who was looking out for his best interests. This person gave him notification of something that he needed to be aware of. It could have been by sending an anonymous message, for instance.
This friend is not his friend, but just a friend of him.
It would be more idiomatic, however, to hear the expression:
I've been a friend of his for years—he just hasn't known it.
So, although the use of him in your first sentence is not actually wrong, it's uncommon and likely sounds strange because it's not something you'll have heard. (And it also means something different than what people would normally be trying to express with it.)
In almost every situation, you should be using his.