If you ask me, this passage seems out of place. Jesus has been on a straight trajectory of tension with the religious elite, but here he seems to come back into cordial theological conversation. The Sadducees were an elite group who did not believe in the resurrection of the dead, and here they come questioning him about resurrection, possibly for two reasons. One, they may have heard him referring to resurrection at some other time and now want to challenge him on it. Two, they want to see just what kind of theological chops he’s got- can he roll with them? The answer is of course an emphatic yes.
With all of that in mind, I do see one reason why this story is placed here: Resurrection. With Jesus’ death an imminent certainty at this point, the question turns to what will happen when he dies? And knowing what he believes about what will happen when he dies is crucial in how the religious leaders will deal with him when he dies. And Jesus’ answer affirms that that when they kill him, their work will not be done. His followers will likely hope for and expect a resurrection if this is what Jesus believes about the afterlife, and therefore the religious leaders will need to tend to his burial.
Furthermore, look at the names Jesus drops here in regards to the afterlife. The Sadducees speak in generalities, but Jesus gets specific. He names the core fathers of the faith: Abraham, Isaac and Jacob and Moses. And he intimates that they have indeed been resurrected in some form or another. Is it possible that Jesus is lumping himself in with these crucial figures of the faith? Is it possible that he is saying, “if God resurrects them, then God will surely resurrect me just as God was incarnated in me.”