Regarding the usage of to:
to
preposition
2 b —used as a function word to indicate the result of an action or a process
// broken all to pieces
// go to seed
// to their surprise, the train left on time
(M-W)
to
preposition
2.2 Governing a phrase expressing someone's reaction to something.
‘to her astonishment, he smiled’
‘Much to his surprise, this small film has turned out to have wide appeal.
(Lexico)
Regarding the usage of much:
much
determiner
a large amount or to a large degree:
• Much to our surprise, (= we were very surprised that) they accepted our offer.
(Cambridge Dictionary)
So much to his despair means that "he" suffered despair to a great extent (much despair) due to the friend's going back on his word. I personally don't believe it is clear who "he/his" is (who suffered the despair), but presumably it is the first friend (not the one who went back on his word).
Notice that this is not an isolated usage of much to. A common usage is much to someone's surprise:
much to someone's surprise
idiom
Definition of much to someone's surprise
—used to say that someone is very surprised by something
// Much to our surprise, she refused.
(M-W)