How to scale child object when only part of the parent object is scaled
In this particular case, to keep things simple, for a constant offset, you could assign a Shrinkwrap modifier to the cube, target the frame, set to 'Nearest Vertex', and with the Offset in the modifier adjusted to give the desired gap. Here, the frame is being animated using shape-keys.



Perhaps more generally. this time giving a true scale, so the gap scales as well as the cube and inner rim:


Create vertex groups of the inner surfaces of the frame and all of the cube
Create a single-bone armature at the scaling origin
Name the vertex groups the same as the bone
Assign an Armature modifier to the frame and the cube, both targeted on the armature, and both set to 'Vertex Group' using the named vertex groups.




Now scaling the bone will scale all the associated vertices.