Formula + Animation

After Effects Code
r = degreesToRadians(transform.rotation);s = thisComp.width/thisComp.height*Math.abs(Math.sin(r)) + Math.abs(Math.cos(r));[s,s]*100
Derivation
Overview
To find the scale factor, we will first construct a rectangle (black) with half-height of and half-width of (the aspect ratio). Next, we will construct an identical rectangle (red) with rotation about its center. Finally, we will construct a third rectangle (blue) identical to the second but scaled to circumscribe the first rectangle. See the figure below.

To find the scale factor, we must find the length of the half-height of the blue rectangle, that is, .
Setup
We will make use of the Law of Sines. Recall that
where and are side lengths of any triangle, and and are their corresponding opposite angles.
Rearranging
Proof
Using the Law of Sines, find and .
Now, find . Recall that is the half-width of the rectangle.
Plug into .
Notice that .
Combine
Notice that .
Finally, substitute with , and take the absolute value.