The Mavs simply mistook the ref's timout call for the possession call, which the ref had already made.
Kidd didn't confirm possession with the refs(it seems like Dallas might have been relying on the announcers, lol), goofed and called an offensive play, and the Warriors profit.
The ref made the initial calls correctly.
That said, it was a dick move by the ref to just hand the ball to Draymond for the free Warriors basket. When the teams lined up at opposite ends and it was obvious Dallas was confused, the ref should have alerted the Mavs and given them a few extra seconds to get set up.
Maybe Luka's chirping got under the ref's skin and he just wanted to say FU to Dallas without getting anything technically wrong.
I'm not sure what the official rules say about protocal in situations like that, but in my experience the refs will usually give teams the benefit of the doubt and give them a few extra seconds to get set up.