Make sure that both devices have Universal Control: Use a single keyboard and mouse between Mac and iPad.
You can set an option to temporarily disable Universal Control whenever you zoom in on the screen of your Mac, so that it’s easier to zoom in along the edge of the screen. See Copy and paste between your Apple devices