He didnt allow Abraham to kill his son.
There is not single word about masturbation in Bible. There is story of Onan but it is not directly about masturbation. From wiki: `` Also, it has been suggested that God's anger was directed not at the sexual act, but at Onan's disobedience by refusing to impregnate his brother's widow.``

He didn't. He wanted to test Abraham's obedience. There's also the concept of putting God first not matter what. While the Bible doesn't talk about masturbation specifically, it does speak against lust.