This was a smart play by Marc Gasol. His plan was clearly to make a kick-out pass, but once he was fouled and knew he had continuation he changed his mind mid-air (as much as Gasol gets air) and threw the ball at the basket. That is completely legal. And smart.
Getting the shot to fall, that is just lucky.
Not that it helped much, the Grizzlies got run over by the Thunder.