“Surely having sex with the widow would not be despicable, since that is what the law required. “
He was having sex under false pretenses. He was only allowed to have sex with her for the purpose of creating an heir. Otherwise, it was sex outside of marriage.
He let everyone believe he was trying to give her (and thus his brother) an heir, but in reality he was just going there to have fun screwing the woman, who could not defend herself. It was a form of rape.
The punishment for all that, with all the spin you’d like to put on it, was for the widow to remove his shoe publicly and spit on him. Not death.