According the Guardian, Bieber actually challenged Sheeran to this stunt, and Sheeran was only too happy to oblige.
“We’d been out to a dive bar. He just drank water and I got hammered,” Sheeran said. “Then we went to a golf course, and he lay on the floor and put a golf ball in his mouth and told me to hit it out of his mouth. I was like, ‘F—, I need to aim this properly,’ and I swung.”
“And you know in films when someone gets punched, and you hear that fake sound, like a slap?” Sheeran said. “But in real life when someone gets punched, you hear that dull thud, a bit sickening? I heard a sound like the last one.”