It sounds like you're using the Crop& Zoom tool, which is a quick way to get smooth motion but also suffers from the issue you mention of sometimes having the edge of the frame move off of the content. There haven't been any improvements in that area since PD15, so you're left with two choices.
If you want to continue to use the tool, one way to keep the frame on the content is to add a keyframe right where the frame edge leaves the content then add a 2nd, duplicate keyframe right away. That will force PD's motion algorithm to halt there and then start a new vector towards the next keyframe. It takes practice, experimentation, and patience, but it can be done.
An alternate approach is to adjust the keyframe that the frame comes back on the content for and move its screen position away from the edge so that the frame never leaves the content on the path from the previous keyframe. Again, you'll need to experiment to get the right feel for this adjustment.
The other main choice would be to skip the tool and go straight to the PiP Designer, where all aspects of keyframing are available and
only the motion you set up will occur. You can use ease-in/ease-out to adjust the velocity of the sweep at and between the keyframes and also specify the exact path you want the zoomed window to take. This method can be more time-consuming but it will always give you predictable results.